belongsToMany(Grade::class); } public function teachers(): BelongsToMany { return $this->belongsToMany(Teacher::class); } public function students(): BelongsToMany { return $this->belongsToMany(Student::class)->using(Score::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%"]); }); } public function user(): MorphOne { return $this->morphOne(User::class, 'userable'); } }