CourseWork/app/Models/Subject.php
2024-04-17 10:11:31 +04:00

32 lines
682 B
PHP

<?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;
class Subject extends Model
{
use HasFactory;
protected $fillable = [
'name',
];
public function grades(): BelongsToMany
{
return $this->belongsToMany(Grade::class);
}
public function scopeFilter(Builder $query): void
{
$name = request('name');
$query->when($name, function (Builder $query, $name) {
$query->whereRaw('name ilike ?', ["$name%"]);
});
}
}