newTab ? 'target="_blank"' : '' }}>
{{ $item->name }}
diff --git a/src/Controllers/Makers/Maker.php b/src/Controllers/Makers/Maker.php
index e5ae18a..b8070b3 100644
--- a/src/Controllers/Makers/Maker.php
+++ b/src/Controllers/Makers/Maker.php
@@ -4,6 +4,7 @@
use Illuminate\Contracts\View\View as ViewContracts;
use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use T0team\LaravelPanel\Enums\Color;
use T0team\LaravelPanel\Traits\MakerTrait;
@@ -86,12 +87,13 @@ private function handleSidebarGroup(array $data): ?object
];
}
- private function handleSidebarItem(array $item): object
+ private function handleSidebarItem(array $item): ?object
{
// get route url
- $url = route($item['route']);
+ $url = $this->getItemUrl($item);
+ if (is_null($url)) return null;
- // check module has badge
+ // check item has badge
if (isset($item['badge'])) {
$badge = $this->handleBadge($item['badge']);
}
@@ -100,11 +102,27 @@ private function handleSidebarItem(array $item): object
'url' => $url,
'name' => $item['item'],
'icon' => $item['icon'],
- 'active' => in_array(request()->route()->getName(), [$item['route'], ...$item['activeIn'] ?? []]),
+ 'active' => in_array(request()->route()->getName(), [$item['route'] ?? [], ...$item['activeIn'] ?? []]),
'badge' => $badge ?? false,
+ 'newTab' => $item['newTab'] ?? false,
];
}
+ private function getItemUrl(array $item): ?string
+ {
+ // check route exists
+ if (isset($item['route']) && Route::has($item['route'])) {
+ return route($item['route']);
+ }
+
+ // check url exists
+ if (isset($item['url'])) {
+ return $item['url'];
+ }
+
+ return null;
+ }
+
private function handleSidebarModule(string $name): ?object
{
// check application use modules