belongsToMany(Subject::class); } public function students(): HasMany { return $this->hasMany(Student::class); } public function teachers(): BelongsToMany { return $this->belongsToMany(Teacher::class); } public function lessons(): HasMany { return $this->hasMany(Lesson::class); } public function scopeFilter(Builder $query): void { $name = request('name'); $query->when($name, function (Builder $query, $name) { $query->whereRaw('name ilike ?', ["$name%"]); }); } }