builder; } return $this->builder->where(function ($query) use ($filter) { $query->where('description', 'like', '%'.$filter.'%') ->orWhere('custom_value1', 'like', '%'.$filter.'%') ->orWhere('custom_value2', 'like', '%'.$filter.'%') ->orWhere('custom_value3', 'like', '%'.$filter.'%') ->orWhere('custom_value4', 'like', '%'.$filter.'%'); }); } /** * Filter based on client status. * * Statuses we need to handle * - all * - invoiced * * @param string client_status The invoice status as seen by the client * @return Builder */ public function client_status(string $value = ''): Builder { if (strlen($value) == 0) { return $this->builder; } $status_parameters = explode(',', $value); if (in_array('all', $status_parameters)) { return $this->builder; } if (in_array('invoiced', $status_parameters)) { $this->builder->whereNotNull('invoice_id'); } return $this->builder; } public function project_tasks($project): Builder { if (strlen($project) == 0) { return $this->builder; } return $this->builder->where('project_id', $this->decodePrimaryKey($project)); } public function number(string $number = ''): Builder { if (strlen($number) == 0) { return $this->builder; } return $this->builder->where('number', $number); } /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); if (!is_array($sort_col) || count($sort_col) != 2) { return $this->builder; } return $this->builder->orderBy($sort_col[0], $sort_col[1]); } /** * Filters the query by the users company ID. * * @return Builder */ public function entityFilter(): Builder { return $this->builder->company(); } }