Merge pull request #9011 from turbo124/v5-develop

Update project filters to allow filtering and sorting by client
This commit is contained in:
David Bomba 2023-12-03 07:40:11 +11:00 committed by GitHub
commit dbcc9008b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;
}