builder; } return $this->builder->where(function ($query) use ($filter) { $query->where('name', 'like', '%'.$filter.'%'); }); } /** * 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 { /** @var \App\Models\User $user */ $user = auth()->user(); return $this->builder->where(function ($query) use($user){ $query->where('company_id', $user->company()->id)->orWhere('company_id', null)->orderBy('id', 'asc'); }); } /** * Filter the designs by `is_custom` column. * * @return Builder */ public function custom(string $custom): Builder { if (strlen($custom) === 0) { return $this->builder; } return $this->builder->where('is_custom', filter_var($custom, FILTER_VALIDATE_BOOLEAN)); } }