Good afternoon. I have a count that seems to work but it’s not visible in the blade.
In the Controller:
public function render()
{
$projekte = Project::orderBy('id','desc')->paginate(10);
$count = Project::withCount('games')
->get();
//dd($count);
return view('livewire.projects.project-overview', compact ('projekte','count'));
}
in the blade
@foreach($projekte as $project)
<p>{{$project->games_count}} </p>
@endforeach
If I DD the $games I can see the correct amount.
I don’t understand what’s wrong.
2
Answers
The answer from ceejayoz was the correct one. You probably want just
Project::orderBy('id','desc')->withCount('games')->paginate(10).
The entire$count = ...
line can go.$projekte
doesn't know about$count
, so the count won't be in your foreach. – ceejayoz 27 mins agoYou are printing the verifiable "$count" and accessing the project variable in the view file.
You can act in this manner.
After that, you can access the file in your view as follows.
Happy Coding!…