belongsTo(Company::class); } /** * The two narrowings the notes screen offers. Each is taken for its truth * value, so a filter of "0" cannot be told apart from one never sent. * * @param array $filters */ public function scopeApplyFilters(Builder $query, array $filters): void { $type = $filters['type'] ?? null; if ($type) { $query->whereType($type); } $search = $filters['search'] ?? null; if ($search) { $query->whereSearch($search); } } public function scopeWhereSearch(Builder $query, string $search): void { $query->where('name', 'LIKE', "%{$search}%"); } public function scopeWhereType(Builder $query, string $type): Builder { return $query->where('type', $type); } /** * Restrict to the company the request is acting for. The column is * table-qualified so the scope survives being hung off a joined query. */ public function scopeWhereCompany(Builder $query): void { $company = request()->header('company'); $query->where('notes.company_id', $company); } }