CourseWork/app/Models/Grade.php

48 lines
1.0 KiB
PHP
Raw Normal View History

2024-04-16 13:27:51 +04:00
<?php
namespace App\Models;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2024-04-17 10:11:31 +04:00
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
2024-04-17 11:16:08 +04:00
use Illuminate\Database\Eloquent\Relations\HasMany;
2024-04-16 13:27:51 +04:00
class Grade extends Model
{
use HasFactory;
protected $fillable = [
'name',
];
2024-04-17 10:11:31 +04:00
public function subjects(): BelongsToMany
{
return $this->belongsToMany(Subject::class);
}
2024-04-17 11:16:08 +04:00
public function students(): HasMany
{
return $this->hasMany(Student::class);
}
public function teachers(): BelongsToMany
{
return $this->belongsToMany(Teacher::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
2024-04-16 13:27:51 +04:00
{
$name = request('name');
$query->when($name, function (Builder $query, $name) {
$query->whereRaw('name ilike ?', ["$name%"]);
});
}
}