self::CONTENT_TYPE_DYNAMIC, ]; protected $fillable = [ 'code', 'label', 'parent_menu_code', 'content_type', 'static_content_schema', 'route', ]; protected function casts(): array { return [ 'static_content_schema' => 'array', ]; } protected static function booted(): void { static::saving(function (self $menu): void { if ( $menu->content_type === self::CONTENT_TYPE_STATIC && empty($menu->static_content_schema) ) { throw ValidationException::withMessages([ 'static_content_schema' => __('api.menu.schema_required'), ]); } }); } public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_menu_code', 'code'); } public function children(): HasMany { return $this->hasMany(self::class, 'parent_menu_code', 'code'); } public function tenants(): BelongsToMany { return $this->belongsToMany( Tenant::class, 'tenants_menues', 'menu_code', 'tenant_code', 'code', 'codigo' ) ->using(TenantMenu::class) ->withPivot('static_content') ->withTimestamps(); } public function roles(): BelongsToMany { return $this->belongsToMany( Role::class, 'roles_menues', 'menu_codigo', 'rol_codigo', 'code', 'codigo' )->using(MenuRole::class); } }