@founderstartup Have you tried without a quote in $item->id?
e.g.
$totallistings = App\Models\Listings::whereHas('project.builder', function ($query) use ($item) {
$query->where('id', $item->id);
})->count();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to show total 'listings' in 'projects' of a 'builder'
$totallistings = App\Models\Listings::whereHas('project.builder', function ($query) {$query->where('id','$item->id');})->count();
listings is related to projects project is related to builder
Its giving nill count.
You also need to import $item to the scope
$totallistings = App\Models\Listings::whereHas('project.builder', function ($query) use ($item) {//here
$query->where('id', $item->id);
})->count();
Please or to participate in this conversation.