Level 24
Are you using models and relationships?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have 3 tables with relationships
Projects ProjectEvaluations => project_id Observations => project_id
I need to generate two counts, one for qty of project evaluations and other one for observations
Like this
How can I do?
-----------.------------
count 1 | count 2 |
10 3
------------------------
You can use withCount():
$projects = Project::withCount('evaluations', 'observations')->get();
foreach($projects as $project) {
// $project->evaluations_count
// $project->observations_count
}
Please or to participate in this conversation.