CourseWork/app/Models/Grade.php

32 lines
684 B
PHP
Raw Permalink 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-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);
}
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%"]);
});
}
}