Why my collection is empty when I send it?
I’m working with Laravel 5 and I’ve the following method in my Controller:
/**
* Display the specified resource.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function show($id)
{
$authUser = Auth::user();
$sharesList = Group::find($id)->shares->sortByDesc('created_at');
$groupList = $authUser->groupsAsMember->where('id', '<>', $id);
$group = $authUser->groups->find($id);
$postList = Group::find($id)->posted->sortByDesc('created_at');
$postsGroups = PostGroup::where('group_id', $id)->with('commented')->get();
//$commentsList;
foreach ($postsGroups as $postGroup) {
$commentsList = $postGroup->commented;
//dd($commentsList);
}
//dd($commentsList);
return view('Pages.Group.detail', ['sharesList' => $sharesList, 'groupList' => $groupList, 'theGroup' => $group, 'postList' => $postList, 'commentsList' => $commentsList]);
}
The problem is of the $commentsList
collection, if I put a dd($commentsList)
inside the @foreach, I can see there’s the elements that I want inside it, but if I put the dd($commentsList)
outside the foreach (after @endforeach) $commentsList is empty and it arrives empty to my HTML page, how can I solve?
I tried to put $commentsList;
before the @foreach loop but still not working.
from Laravel Questions and Answers https://laravelquestions.com/php/why-my-collection-is-empty-when-i-send-it/
via Lzo Media
No comments:
Post a Comment