2024-04-17 10:11:31 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2024-05-08 12:15:55 +04:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2024-04-17 13:02:44 +04:00
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
2024-04-17 10:11:31 +04:00
|
|
|
|
|
|
|
class Subject extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function grades(): BelongsToMany
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Grade::class);
|
|
|
|
}
|
|
|
|
|
2024-04-17 11:16:08 +04:00
|
|
|
public function teachers(): BelongsToMany
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Teacher::class);
|
|
|
|
}
|
|
|
|
|
2024-05-07 17:15:58 +04:00
|
|
|
public function students(): BelongsToMany
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Student::class)->using(Score::class);
|
|
|
|
}
|
|
|
|
|
2024-05-08 12:15:55 +04:00
|
|
|
public function lessons(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(Lesson::class);
|
|
|
|
}
|
|
|
|
|
2024-04-17 10:11:31 +04:00
|
|
|
public function scopeFilter(Builder $query): void
|
|
|
|
{
|
|
|
|
$name = request('name');
|
|
|
|
|
|
|
|
$query->when($name, function (Builder $query, $name) {
|
|
|
|
$query->whereRaw('name ilike ?', ["$name%"]);
|
|
|
|
});
|
|
|
|
}
|
2024-04-17 13:02:44 +04:00
|
|
|
|
|
|
|
public function user(): MorphOne
|
|
|
|
{
|
|
|
|
return $this->morphOne(User::class, 'userable');
|
|
|
|
}
|
2024-04-17 10:11:31 +04:00
|
|
|
}
|