Update project filters to allow filtering and sorting by client

This commit is contained in:
David Bomba 2023-12-02 16:17:16 +11:00
parent c14d73cda4
commit 2d33230539

View File

@ -33,6 +33,9 @@ class ProjectFilters extends QueryFilters
return $this->builder->where(function ($query) use ($filter) {
$query->where('name', 'like', '%'.$filter.'%')
->orWhereHas('client', function ($q) use ($filter) {
$q->where('name', 'like', '%'.$filter.'%');
})
->orWhere('public_notes', 'like', '%'.$filter.'%')
->orWhere('private_notes', 'like', '%'.$filter.'%');
});
@ -57,6 +60,11 @@ class ProjectFilters extends QueryFilters
{
$sort_col = explode('|', $sort);
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'projects.client_id'), $sort_col[1]);
}
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}