Skip to content

Commit

Permalink
add filament navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Aug 4, 2023
1 parent 4ed57d9 commit 3841b82
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
10 changes: 2 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"php": "^8.1",
"ext-json": "*",
"doctrine/dbal": "^3.5.1",
"ryangjchandler/filament-navigation": "dev-filament3",
"ryangjchandler/filament-navigation": "^1.0",
"filament/spatie-laravel-media-library-plugin": "^3.0@beta",
"filament/spatie-laravel-tags-plugin": "^3.0@beta",
"spatie/laravel-medialibrary": "^10.0.0",
Expand Down Expand Up @@ -87,11 +87,5 @@
]
}
},
"minimum-stability": "dev",
"repositories": [
{
"type": "git",
"url": "[email protected]:atmonshi/filament-navigation.git"
}
]
"minimum-stability": "dev"
}
32 changes: 31 additions & 1 deletion src/SkyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace LaraZeus\Sky;

use Filament\Contracts\Plugin;
use Filament\Forms\Components\Select;
use Filament\Panel;
use LaraZeus\Sky\Filament\Resources\FaqResource;
use LaraZeus\Sky\Filament\Resources\LibraryResource;
use LaraZeus\Sky\Filament\Resources\PageResource;
use LaraZeus\Sky\Filament\Resources\PostResource;
use LaraZeus\Sky\Filament\Resources\TagResource;
use RyanChandler\FilamentNavigation\FilamentNavigation;

class SkyPlugin implements Plugin
{
Expand Down Expand Up @@ -38,14 +40,42 @@ public function register(Panel $panel): void
}

$panel->resources([TagResource::class]);

$panel->plugin(
FilamentNavigation::make()
->itemType(__('Post link'), [
Select::make('post_id')
->label(__('Select Post'))
->searchable()
->options(function () {
return SkyPlugin::get()->getPostModel()::published()->pluck('title', 'id');
}),
])
->itemType(__('Page link'), [
Select::make('page_id')
->label(__('Select Page'))
->searchable()
->options(function () {
return SkyPlugin::get()->getPostModel()::page()->pluck('title', 'id');
}),
])
->itemType(__('Library link'), [
Select::make('library_id')
->label(__('Select Library'))
->searchable()
->options(function () {
return SkyPlugin::get()->getTagModel()::getWithType('library')->pluck('name', 'id');
}),
])
);
}

public static function make(): static
{
return app(static::class);
}

public static function get(): Plugin | \Filament\FilamentManager
public static function get(): Plugin|\Filament\FilamentManager
{
return filament(app(static::class)->getId());
}
Expand Down
36 changes: 3 additions & 33 deletions src/SkyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
namespace LaraZeus\Sky;

use Filament\Facades\Filament;
use Filament\Forms\Components\Select;
use LaraZeus\Core\CoreServiceProvider;
use LaraZeus\Sky\Console\migrateCommand;
use LaraZeus\Sky\Console\PublishCommand;
use RyanChandler\FilamentNavigation\Facades\FilamentNavigation;
use RyanChandler\FilamentNavigation\Filament\Resources\NavigationResource;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down Expand Up @@ -62,43 +60,15 @@ protected function getMigrations(): array

private function bootFilamentNavigation(): void
{
if (! array_key_exists('zeus-sky', app('filament')->getCurrentPanel()->getPlugins())) {
if (!app('filament')->hasPlugin('zeus-sky')) {
return;
}

NavigationResource::navigationGroup(SkyPlugin::get()->getNavigationGroupLabel());
NavigationResource::navigationSort(999);

NavigationResource::navigationIcon('heroicon-o-queue-list');
NavigationResource::navigationLabel(__('Navigations'));
NavigationResource::pluralLabel(__('Navigations'));
NavigationResource::label(__('Navigation'));

NavigationResource::navigationIcon('heroicon-o-queue-list');

FilamentNavigation::addItemType(__('Post link'), [
Select::make('post_id')
->label(__('Select Post'))
->searchable()
->options(function () {
return SkyPlugin::get()->getPostModel()::published()->pluck('title', 'id');
}),
]);

FilamentNavigation::addItemType(__('Page link'), [
Select::make('page_id')
->label(__('Select Page'))
->searchable()
->options(function () {
return SkyPlugin::get()->getPostModel()::page()->pluck('title', 'id');
}),
]);

FilamentNavigation::addItemType(__('Library link'), [
Select::make('library_id')
->label(__('Select Library'))
->searchable()
->options(function () {
return SkyPlugin::get()->getTagModel()::getWithType('library')->pluck('name', 'id');
}),
]);
}
}

0 comments on commit 3841b82

Please sign in to comment.