Skip to content

Commit

Permalink
add configuration for slug, label and navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
gexcube committed May 20, 2023
1 parent 385094d commit eb67c2c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ return [
'blog:delete' => 'Delete Blog',
],
'columns' => 4,
'navigation_menu' => true,
'user_menu' => false,
'label' => 'Sanctum',
'slug' => 'sanctum',

];
```
Expand Down
4 changes: 4 additions & 0 deletions config/filament-sanctum.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
'blog:delete' => 'Delete Blog',
],
'columns' => 4,
'navigation_menu' => true,
'user_menu' => false,
'label' => 'Sanctum',
'slug' => 'sanctum',

];
16 changes: 12 additions & 4 deletions src/Pages/Sanctum.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ class Sanctum extends Page implements Tables\Contracts\HasTable

protected static string $view = 'filament-sanctum::pages.sanctum';

protected static ?string $slug = 'sanctum';
public static function getSlug(): string
{
return config('filament-sanctum.slug');
}

protected function getTitle(): string
{
return trans('Sanctum');
return trans(config('filament-sanctum.label'));
}

protected static function getNavigationLabel(): string
{
return trans('Sanctum');
return trans(config('filament-sanctum.label'));
}

protected static function shouldRegisterNavigation(): bool
{
return config('filament-sanctum.navigation_menu');
}

protected function getTableQuery(): Builder
Expand Down Expand Up @@ -83,7 +91,7 @@ protected function getActions(): array
->title(trans('Token was created successfully'))
->send();

return redirect(config('filament.path').'/sanctum');
return redirect(route('filament.pages.'.config('filament-sanctum.slug')));
})
->form([
Forms\Components\TextInput::make('name')
Expand Down
11 changes: 11 additions & 0 deletions src/SanctumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Devtical\Sanctum\Pages\Sanctum;
use Filament\PluginServiceProvider;
use Spatie\LaravelPackageTools\Package;
use Filament\Navigation\UserMenuItem;

class SanctumServiceProvider extends PluginServiceProvider
{
Expand All @@ -25,4 +26,14 @@ public function configurePackage(Package $package): void
->hasAssets('filament-sanctum')
->hasTranslations();
}

protected function getUserMenuItems(): array
{
return config('filament-sanctum.user_menu') ? [
UserMenuItem::make()
->label(trans(config('filament-sanctum.label')))
->url(route('filament.pages.'.config('filament-sanctum.slug')))
->icon('heroicon-s-cog'),
] : [];
}
}

0 comments on commit eb67c2c

Please sign in to comment.