<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MenuItem extends Model
{
protected $fillable = [
'label', 'url', 'route_name', 'location',
'icon', 'target', 'sort_order', 'is_enabled',
];
protected $casts = [
'is_enabled' => 'boolean',
];
public static function forLocation(string $location)
{
return static::where('location', $location)
->where('is_enabled', true)
->orderBy('sort_order')
->get();
}
public function isActive(): bool
{
if ($this->route_name) {
return request()->routeIs($this->route_name);
}
return request()->url() === $this->url;
}
}