<?php

namespace Modules\Menu\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Cache;
use Spatie\Translatable\HasTranslations;

class MenuColumn extends Model
{
    use HasFactory , HasTranslations;

    protected $guarded = ['id'];
    public $translatable = ['column'];
    public function __construct(array $attributes = [])
    {

    }

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

        self::created(function ($model) {
            Cache::forget('MegaMenu');
        });
        self::updated(function ($model) {
            Cache::forget('MegaMenu');
        });
        self::deleted(function ($model) {
            Cache::forget('MegaMenu');
        });

    }

    public function elements(){
        return $this->hasMany(MenuElement::class,'column_id','id')->orderBy('position');
    }

}
