brand filter for cars
parent
46d0dc7ad8
commit
537d5b8e49
|
|
@ -191,12 +191,12 @@ class CarController extends Controller
|
|||
$cars = $this->getWithCustomSort($cars, $sortBy, $direction);
|
||||
|
||||
return Inertia::render($renderPage, [
|
||||
'filters' => $request->all('search', 'trashed'),
|
||||
'filters' => $request->all('search', 'trashed', 'brand'),
|
||||
'sort' => [
|
||||
'by' => $sortBy,
|
||||
'direction' => $direction,
|
||||
],
|
||||
'cars' => $cars->filter($request->only('search', 'trashed'))
|
||||
'cars' => $cars->filter($request->only('search', 'trashed', 'brand'))
|
||||
->paginate(50)
|
||||
->withQueryString()
|
||||
->through(fn ($car) => [
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class Car extends Model
|
|||
|
||||
public function scopeSoldOnly($query)
|
||||
{
|
||||
return $query->withContractCount()->having('sell_contracts_count', '>', 0)->havingRaw('buy_contracts_count <= sell_contracts_count');
|
||||
return $query->withContractCount()->having('sell_contracts_count', '>', 0)->havingRaw('buy_contracts_count = sell_contracts_count');
|
||||
}
|
||||
|
||||
public function scopeFilter($query, array $filters)
|
||||
|
|
@ -150,6 +150,12 @@ class Car extends Model
|
|||
} elseif ($trashed === 'only') {
|
||||
$query->onlyTrashed();
|
||||
}
|
||||
})->when($filters['brand'] ?? null, function ($query, $brand) {
|
||||
$query->whereHas('carModel', function($q) use ($brand)
|
||||
{
|
||||
$q->where('brand_id', '=', $brand);
|
||||
|
||||
})->get();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue