I'm trying to build a simple form based query system. It'll show all the queries and their responses to the user.
In controller, I'm returning questions model where user ID is Auth::id() .
Here's my schema:
| id | user_id | lesson_name | statement | statement_type |
|--- | ------- | ----------- | ------------------ | -------------- |
| 1 | 1 | python | Any question asked | question |
| 2 | 1 | python | Response by admin | response |
I want to show all the entries related to a user for a particular lesson. Here's what I've done till now:
In the controller
$queries = Question::where('user_id', Auth::id())->get()->groupBy('lesson_name');
In blade file
@foreach ($queries as $query)
<div class="query-wrapper card">
<a href="#" class="query-video-thumbnail"><img src="{{ asset('img/signup.jpg') }}"
class="query-video-thumbnail"></a>
<div class="vertical-wrapper query-wrapper-content" onclick="openQueryPopup()">
<h2 class="query-lesson-name">{{ $query->value('lesson_name') }}</h2>
<p class="query-msg">Query message will show up here...</p>
<p class="sender">Sangam replied</p>
</div>
<div class="vertical-wrapper">
<a href="#" class="query-reply">Reply <i class="bi bi-send-fill"></i>
</a>
</div>
</div>
<div id="query-container" class="query-container card">
<h4>
Your query about
<br>
Lesson name will appear here
</h4>
<div class="vertical-wrapper receiver-msg-div">
@foreach ($query->pluck('statement_type') as $statementtype)
<p class="sender">{{ $statementtype }}:</p>
<p class="query-msg">{{ $query->value('statement') }}</p>
@endforeach
</div>
<div class="vertical-wrapper">
<a href="#" class="query-reply">Reply <i class="bi bi-send-fill"></i>
</a>
</div>
</div>
<div id="pseudo-container" onclick="closeQueryPopup()"></div>
@endforeach
I'm not able to fetch statement_type and statement at the same time.
Any help is appreciated.
Edit 1
I simply want to loop all statements of auth()->user() with headings of statement_type