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