'boolean', 'route_params' => 'json', ]; public function parent() { return $this->belongsTo(NavbarLink::class, 'parent_id'); } public function children() { return $this->hasMany(NavbarLink::class, 'parent_id')->orderBy('sort_order'); } public function product() { return $this->belongsTo(\App\Models\Product::class); } public function category() { return $this->belongsTo(\App\Models\Category::class); } public function scopeActive($query) { return $query->where('is_active', true); } public function scopeTopLevel($query) { return $query->whereNull('parent_id'); } public function scopeByType($query, $type) { return $query->where('type', $type); } protected static function booted() { static::saving(function ($link) { // Clear unused fields based on link_type switch ($link->link_type) { case 'route': $link->custom_path = null; $link->custom_url = null; $link->product_id = null; $link->category_id = null; break; case 'path': $link->route_name = null; $link->route_params = null; $link->custom_url = null; $link->product_id = null; $link->category_id = null; break; case 'url': $link->route_name = null; $link->route_params = null; $link->custom_path = null; $link->product_id = null; $link->category_id = null; break; case 'product': $link->route_name = null; $link->route_params = null; $link->custom_path = null; $link->custom_url = null; $link->category_id = null; break; case 'category': $link->route_name = null; $link->route_params = null; $link->custom_path = null; $link->custom_url = null; $link->product_id = null; break; } }); } }