<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Menu extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    protected static function boot()
    {
        parent::boot();

        static::deleting(function ($menu) {
            $menu->items()->delete();
        });
    }

    public function items()
    {
        return $this->hasMany(MenuItem::class)->orderBy('order');
    }
}
