Level 55
@founderstartup https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-existence
$listingcount = App\Models\Listings::whereHas('project.city', fn($query) => $query->where('id', $item->id))->count();
or if project belongsTo city (has 'city_id' column)
$listingcount = App\Models\Listings::whereHas('project', fn($query) => $query->where('city_id', $item->id))->count();
1 like