belongsToMany(Subject::class); } public function grades(): BelongsToMany { return $this->belongsToMany(Grade::class); } public function user(): MorphOne { return $this->morphOne(User::class, 'userable'); } public function scopeFilter(Builder $query): void { $name = request('name'); $query->when($name, function (Builder $query, $name){ $query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (surname, \' \', patronymic, \' \', name) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (patronymic, \' \', name, \' \', surname) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (patronymic, \' \', surname, \' \', name) ilike ?', ["$name%"]); }); } public function fio(): Attribute { return Attribute::make( get: fn () => $this->last_name . " " . $this->name . " " . $this->middle_name, ); } }