feat: enhance CreditsPlus and NavbarManager extensions with improved role checks, route handling, and migration logic for better functionality and compatibility across databases
This commit is contained in:
@@ -60,9 +60,9 @@ class NavigationLinks extends Component
|
||||
case 'always_hidden':
|
||||
return false;
|
||||
case 'clients_only':
|
||||
return auth()->check() && auth()->user()->role_id === null;
|
||||
return auth()->check() && auth()->user()->role === null;
|
||||
case 'admin_only':
|
||||
return auth()->check() && auth()->user()->role_id !== null;
|
||||
return auth()->check() && auth()->user()->role !== null;
|
||||
case 'guests_only':
|
||||
return !auth()->check();
|
||||
default:
|
||||
@@ -81,9 +81,11 @@ class NavigationLinks extends Component
|
||||
'priority' => $link->sort_order,
|
||||
];
|
||||
|
||||
// Add icon
|
||||
if ($link->icon) {
|
||||
$formatted['icon'] = $link->icon;
|
||||
// Add icon with validation and strip -line/-fill suffix
|
||||
if ($link->icon && $this->isValidIcon($link->icon)) {
|
||||
// Remove -line or -fill suffix since Navigation::markActiveRoute will add it
|
||||
$baseIcon = preg_replace('/-(?:line|fill)$/', '', $link->icon);
|
||||
$formatted['icon'] = $baseIcon;
|
||||
}
|
||||
|
||||
// Handle different link types
|
||||
@@ -91,10 +93,13 @@ class NavigationLinks extends Component
|
||||
case 'route':
|
||||
if ($link->route_name) {
|
||||
$formatted['route'] = $link->route_name;
|
||||
$formatted['spa'] = true; // Enable SPA for route links
|
||||
if ($link->route_params) {
|
||||
$params = is_string($link->route_params)
|
||||
? json_decode($link->route_params, true)
|
||||
: $link->route_params;
|
||||
// Get raw attribute to avoid accessor transformation
|
||||
$rawParams = $link->getAttributes()['route_params'] ?? null;
|
||||
$params = is_string($rawParams)
|
||||
? json_decode($rawParams, true)
|
||||
: $rawParams;
|
||||
if ($params && is_array($params)) {
|
||||
$formatted['params'] = $params;
|
||||
}
|
||||
@@ -104,10 +109,50 @@ class NavigationLinks extends Component
|
||||
}
|
||||
break;
|
||||
case 'path':
|
||||
$formatted['direct_url'] = $link->custom_path;
|
||||
break;
|
||||
case 'url':
|
||||
$formatted['direct_url'] = $link->custom_url;
|
||||
// Use navbar redirect route
|
||||
$formatted['route'] = 'navbar.redirect';
|
||||
$formatted['params'] = ['linkId' => $link->id];
|
||||
$formatted['spa'] = false; // Disable SPA for external links
|
||||
break;
|
||||
case 'product':
|
||||
if ($link->product_id) {
|
||||
try {
|
||||
$product = \App\Models\Product::with('category')->find($link->product_id);
|
||||
if ($product && $product->category) {
|
||||
$formatted['route'] = 'products.show';
|
||||
$formatted['params'] = [
|
||||
'category' => $product->category->slug ?? $product->category->id,
|
||||
'product' => $product->slug ?? $product->id
|
||||
];
|
||||
$formatted['spa'] = true;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
case 'category':
|
||||
if ($link->category_id) {
|
||||
try {
|
||||
$category = \App\Models\Category::find($link->category_id);
|
||||
if ($category) {
|
||||
$formatted['route'] = 'category.show';
|
||||
$formatted['params'] = ['category' => $category->slug ?? $category->id];
|
||||
$formatted['spa'] = true;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -136,4 +181,13 @@ class NavigationLinks extends Component
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function isValidIcon($icon)
|
||||
{
|
||||
// Basic validation for RemixIcon format
|
||||
if (!preg_match('/^ri-[\w-]+$/', $icon)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user