I used laravel hasmany relationship in my user model. I just want to convert my table like below (row to column):
To:
Here is my User
model:
public function meal(){
return $this->hasMany(Meal::class);
}
My controller:
public function index()
{
$members = User::all();
return view('admin.meal')->with([
'members' => $members,
]);
}
and @blade
<table class="table table-striped @if(count($members)>7) table-responsive @endif ">
<thead>
<tr class="text-uppercase">
{{--<th class="font-w700">Date</th>--}}
@foreach($members as $member)
<th class="font-w700">{{str_limit($member->fname,5,'...')}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($members as $member)
<tr>
@foreach($member->meal as $meal)
<td><span class="font-w600">{{$meal->user_id}}</span></td>
@endforeach
</tr>
@endforeach
</tbody>
</table>