From e67fa9d77b5739249828d79e92a76b3be4e01b7e Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Mon, 6 Nov 2023 17:27:27 +0300 Subject: [PATCH] allow to hide Resources from Navigation --- composer.lock | 162 +++++++++--------- docs/getting-started/configuration.md | 14 ++ src/Configuration.php | 14 ++ src/Filament/Resources/NavigationResource.php | 38 +--- src/Filament/Resources/SkyResource.php | 5 + src/SkyServiceProvider.php | 8 - 6 files changed, 123 insertions(+), 118 deletions(-) diff --git a/composer.lock b/composer.lock index 8cb3896..b649351 100644 --- a/composer.lock +++ b/composer.lock @@ -1278,16 +1278,16 @@ }, { "name": "filament/actions", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/actions.git", - "reference": "a8413d87256672c939ef82558ad01350617612a6" + "reference": "a144456ae1296de50e345bb9df857b338fab47ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filamentphp/actions/zipball/a8413d87256672c939ef82558ad01350617612a6", - "reference": "a8413d87256672c939ef82558ad01350617612a6", + "url": "https://api.github.com/repos/filamentphp/actions/zipball/a144456ae1296de50e345bb9df857b338fab47ea", + "reference": "a144456ae1296de50e345bb9df857b338fab47ea", "shasum": "" }, "require": { @@ -1324,20 +1324,20 @@ "issues": "https://github.com/filamentphp/filament/issues", "source": "https://github.com/filamentphp/filament" }, - "time": "2023-10-27T14:34:56+00:00" + "time": "2023-11-03T09:01:10+00:00" }, { "name": "filament/filament", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/panels.git", - "reference": "dfe4b9ed7a5a5f8a3135a9789ee70946590ee11d" + "reference": "7f984f011e49638d7156f976aa0aafbbd3235447" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filamentphp/panels/zipball/dfe4b9ed7a5a5f8a3135a9789ee70946590ee11d", - "reference": "dfe4b9ed7a5a5f8a3135a9789ee70946590ee11d", + "url": "https://api.github.com/repos/filamentphp/panels/zipball/7f984f011e49638d7156f976aa0aafbbd3235447", + "reference": "7f984f011e49638d7156f976aa0aafbbd3235447", "shasum": "" }, "require": { @@ -1389,20 +1389,20 @@ "issues": "https://github.com/filamentphp/filament/issues", "source": "https://github.com/filamentphp/filament" }, - "time": "2023-10-30T09:52:34+00:00" + "time": "2023-11-05T09:01:26+00:00" }, { "name": "filament/forms", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/forms.git", - "reference": "4403c0c047f8516b349edeb56ede07551e259c7d" + "reference": "18f4a87bbe92a479331b606aeddad9a55efac4f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filamentphp/forms/zipball/4403c0c047f8516b349edeb56ede07551e259c7d", - "reference": "4403c0c047f8516b349edeb56ede07551e259c7d", + "url": "https://api.github.com/repos/filamentphp/forms/zipball/18f4a87bbe92a479331b606aeddad9a55efac4f5", + "reference": "18f4a87bbe92a479331b606aeddad9a55efac4f5", "shasum": "" }, "require": { @@ -1445,20 +1445,20 @@ "issues": "https://github.com/filamentphp/filament/issues", "source": "https://github.com/filamentphp/filament" }, - "time": "2023-10-30T09:52:24+00:00" + "time": "2023-11-05T09:01:25+00:00" }, { "name": "filament/infolists", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/infolists.git", - "reference": "f74cc311ba0672c3f73b1cdd802185f8b41fd4cd" + "reference": "66c7d3549d094d63fd3fe6c8de7d5a87ef2d7f0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filamentphp/infolists/zipball/f74cc311ba0672c3f73b1cdd802185f8b41fd4cd", - "reference": "f74cc311ba0672c3f73b1cdd802185f8b41fd4cd", + "url": "https://api.github.com/repos/filamentphp/infolists/zipball/66c7d3549d094d63fd3fe6c8de7d5a87ef2d7f0a", + "reference": "66c7d3549d094d63fd3fe6c8de7d5a87ef2d7f0a", "shasum": "" }, "require": { @@ -1496,20 +1496,20 @@ "issues": "https://github.com/filamentphp/filament/issues", "source": "https://github.com/filamentphp/filament" }, - "time": "2023-10-27T14:35:11+00:00" + "time": "2023-11-03T09:01:14+00:00" }, { "name": "filament/notifications", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/notifications.git", - "reference": "b54eb25ec100e65b960fb8b90c9d38c132eb5bb6" + "reference": "341d60b65808467c16a392b203bb4b772a314395" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filamentphp/notifications/zipball/b54eb25ec100e65b960fb8b90c9d38c132eb5bb6", - "reference": "b54eb25ec100e65b960fb8b90c9d38c132eb5bb6", + "url": "https://api.github.com/repos/filamentphp/notifications/zipball/341d60b65808467c16a392b203bb4b772a314395", + "reference": "341d60b65808467c16a392b203bb4b772a314395", "shasum": "" }, "require": { @@ -1548,11 +1548,11 @@ "issues": "https://github.com/filamentphp/filament/issues", "source": "https://github.com/filamentphp/filament" }, - "time": "2023-10-27T14:34:57+00:00" + "time": "2023-11-05T09:01:18+00:00" }, { "name": "filament/spatie-laravel-media-library-plugin", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/spatie-laravel-media-library-plugin.git", @@ -1589,7 +1589,7 @@ }, { "name": "filament/spatie-laravel-tags-plugin", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/spatie-laravel-tags-plugin.git", @@ -1626,7 +1626,7 @@ }, { "name": "filament/spatie-laravel-translatable-plugin", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/spatie-laravel-translatable-plugin.git", @@ -1671,16 +1671,16 @@ }, { "name": "filament/support", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/support.git", - "reference": "5e5884f71d9529754d4f890319336535e42fc621" + "reference": "087b4908d223852ad714ccf7196db9bea7851f9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filamentphp/support/zipball/5e5884f71d9529754d4f890319336535e42fc621", - "reference": "5e5884f71d9529754d4f890319336535e42fc621", + "url": "https://api.github.com/repos/filamentphp/support/zipball/087b4908d223852ad714ccf7196db9bea7851f9d", + "reference": "087b4908d223852ad714ccf7196db9bea7851f9d", "shasum": "" }, "require": { @@ -1724,20 +1724,20 @@ "issues": "https://github.com/filamentphp/filament/issues", "source": "https://github.com/filamentphp/filament" }, - "time": "2023-10-30T09:52:26+00:00" + "time": "2023-11-05T09:01:21+00:00" }, { "name": "filament/tables", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/tables.git", - "reference": "fa48a1a4abfb501417ed8e5abc71fb36d08ae51e" + "reference": "f854247436abfb833da400f0621689cac2bb2640" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filamentphp/tables/zipball/fa48a1a4abfb501417ed8e5abc71fb36d08ae51e", - "reference": "fa48a1a4abfb501417ed8e5abc71fb36d08ae51e", + "url": "https://api.github.com/repos/filamentphp/tables/zipball/f854247436abfb833da400f0621689cac2bb2640", + "reference": "f854247436abfb833da400f0621689cac2bb2640", "shasum": "" }, "require": { @@ -1777,11 +1777,11 @@ "issues": "https://github.com/filamentphp/filament/issues", "source": "https://github.com/filamentphp/filament" }, - "time": "2023-10-30T09:52:30+00:00" + "time": "2023-11-05T09:01:33+00:00" }, { "name": "filament/widgets", - "version": "v3.0.88", + "version": "v3.0.91", "source": { "type": "git", "url": "https://github.com/filamentphp/widgets.git", @@ -3338,16 +3338,16 @@ }, { "name": "livewire/livewire", - "version": "v3.0.10", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/livewire/livewire.git", - "reference": "cae998aa9a474dc0de81869ab1536014c7b31a64" + "reference": "db1e02c645ae12a7cdee9b1ea0d65bf3aafc0f08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/livewire/zipball/cae998aa9a474dc0de81869ab1536014c7b31a64", - "reference": "cae998aa9a474dc0de81869ab1536014c7b31a64", + "url": "https://api.github.com/repos/livewire/livewire/zipball/db1e02c645ae12a7cdee9b1ea0d65bf3aafc0f08", + "reference": "db1e02c645ae12a7cdee9b1ea0d65bf3aafc0f08", "shasum": "" }, "require": { @@ -3400,7 +3400,7 @@ "description": "A front-end framework for Laravel.", "support": { "issues": "https://github.com/livewire/livewire/issues", - "source": "https://github.com/livewire/livewire/tree/v3.0.10" + "source": "https://github.com/livewire/livewire/tree/v3.1.0" }, "funding": [ { @@ -3408,7 +3408,7 @@ "type": "github" } ], - "time": "2023-10-18T11:18:12+00:00" + "time": "2023-11-03T15:05:18+00:00" }, { "name": "maennchen/zipstream-php", @@ -4990,28 +4990,28 @@ }, { "name": "spatie/image-optimizer", - "version": "1.7.1", + "version": "1.7.2", "source": { "type": "git", "url": "https://github.com/spatie/image-optimizer.git", - "reference": "af179994e2d2413e4b3ba2d348d06b4eaddbeb30" + "reference": "62f7463483d1bd975f6f06025d89d42a29608fe1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/image-optimizer/zipball/af179994e2d2413e4b3ba2d348d06b4eaddbeb30", - "reference": "af179994e2d2413e4b3ba2d348d06b4eaddbeb30", + "url": "https://api.github.com/repos/spatie/image-optimizer/zipball/62f7463483d1bd975f6f06025d89d42a29608fe1", + "reference": "62f7463483d1bd975f6f06025d89d42a29608fe1", "shasum": "" }, "require": { "ext-fileinfo": "*", "php": "^7.3|^8.0", "psr/log": "^1.0 | ^2.0 | ^3.0", - "symfony/process": "^4.2|^5.0|^6.0" + "symfony/process": "^4.2|^5.0|^6.0|^7.0" }, "require-dev": { "pestphp/pest": "^1.21", "phpunit/phpunit": "^8.5.21|^9.4.4", - "symfony/var-dumper": "^4.2|^5.0|^6.0" + "symfony/var-dumper": "^4.2|^5.0|^6.0|^7.0" }, "type": "library", "autoload": { @@ -5039,9 +5039,9 @@ ], "support": { "issues": "https://github.com/spatie/image-optimizer/issues", - "source": "https://github.com/spatie/image-optimizer/tree/1.7.1" + "source": "https://github.com/spatie/image-optimizer/tree/1.7.2" }, - "time": "2023-07-27T07:57:32+00:00" + "time": "2023-11-03T10:08:02+00:00" }, { "name": "spatie/invade", @@ -5111,16 +5111,16 @@ }, { "name": "spatie/laravel-medialibrary", - "version": "10.14.0", + "version": "10.15.0", "source": { "type": "git", "url": "https://github.com/spatie/laravel-medialibrary.git", - "reference": "fde92469e37d580c001b9d146c9454643c6d6d57" + "reference": "f464c82357500c5c68ea350edff35ed9831fd48e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/fde92469e37d580c001b9d146c9454643c6d6d57", - "reference": "fde92469e37d580c001b9d146c9454643c6d6d57", + "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/f464c82357500c5c68ea350edff35ed9831fd48e", + "reference": "f464c82357500c5c68ea350edff35ed9831fd48e", "shasum": "" }, "require": { @@ -5203,7 +5203,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-medialibrary/issues", - "source": "https://github.com/spatie/laravel-medialibrary/tree/10.14.0" + "source": "https://github.com/spatie/laravel-medialibrary/tree/10.15.0" }, "funding": [ { @@ -5215,7 +5215,7 @@ "type": "github" } ], - "time": "2023-10-25T11:26:54+00:00" + "time": "2023-11-03T13:09:19+00:00" }, { "name": "spatie/laravel-package-tools", @@ -8727,16 +8727,16 @@ }, { "name": "filp/whoops", - "version": "2.15.3", + "version": "2.15.4", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "c83e88a30524f9360b11f585f71e6b17313b7187" + "reference": "a139776fa3f5985a50b509f2a02ff0f709d2a546" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/c83e88a30524f9360b11f585f71e6b17313b7187", - "reference": "c83e88a30524f9360b11f585f71e6b17313b7187", + "url": "https://api.github.com/repos/filp/whoops/zipball/a139776fa3f5985a50b509f2a02ff0f709d2a546", + "reference": "a139776fa3f5985a50b509f2a02ff0f709d2a546", "shasum": "" }, "require": { @@ -8786,7 +8786,7 @@ ], "support": { "issues": "https://github.com/filp/whoops/issues", - "source": "https://github.com/filp/whoops/tree/2.15.3" + "source": "https://github.com/filp/whoops/tree/2.15.4" }, "funding": [ { @@ -8794,7 +8794,7 @@ "type": "github" } ], - "time": "2023-07-13T12:00:00+00:00" + "time": "2023-11-03T12:00:00+00:00" }, { "name": "friendsofphp/php-cs-fixer", @@ -9786,16 +9786,16 @@ }, { "name": "orchestra/canvas", - "version": "v8.11.2", + "version": "v8.11.3", "source": { "type": "git", "url": "https://github.com/orchestral/canvas.git", - "reference": "5038b630e2306a8e7486d69628d84fa2d1764cb1" + "reference": "d336a5a5b14a3dbcb2c12888c314d6ea34a8545c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/orchestral/canvas/zipball/5038b630e2306a8e7486d69628d84fa2d1764cb1", - "reference": "5038b630e2306a8e7486d69628d84fa2d1764cb1", + "url": "https://api.github.com/repos/orchestral/canvas/zipball/d336a5a5b14a3dbcb2c12888c314d6ea34a8545c", + "reference": "d336a5a5b14a3dbcb2c12888c314d6ea34a8545c", "shasum": "" }, "require": { @@ -9853,9 +9853,9 @@ "description": "Code Generators for Laravel Applications and Packages", "support": { "issues": "https://github.com/orchestral/canvas/issues", - "source": "https://github.com/orchestral/canvas/tree/v8.11.2" + "source": "https://github.com/orchestral/canvas/tree/v8.11.3" }, - "time": "2023-10-26T21:59:54+00:00" + "time": "2023-11-06T06:10:13+00:00" }, { "name": "orchestra/canvas-core", @@ -9983,16 +9983,16 @@ }, { "name": "orchestra/testbench-core", - "version": "v8.14.3", + "version": "v8.14.4", "source": { "type": "git", "url": "https://github.com/orchestral/testbench-core.git", - "reference": "6ebfa94c5d7872c5a6623ed588476771c6b9c124" + "reference": "2501be03ccd199851006b3d286b303b97fc55738" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/6ebfa94c5d7872c5a6623ed588476771c6b9c124", - "reference": "6ebfa94c5d7872c5a6623ed588476771c6b9c124", + "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/2501be03ccd199851006b3d286b303b97fc55738", + "reference": "2501be03ccd199851006b3d286b303b97fc55738", "shasum": "" }, "require": { @@ -10067,7 +10067,7 @@ "issues": "https://github.com/orchestral/testbench/issues", "source": "https://github.com/orchestral/testbench-core" }, - "time": "2023-10-31T12:58:05+00:00" + "time": "2023-11-02T13:53:10+00:00" }, { "name": "orchestra/workbench", @@ -11028,16 +11028,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.40", + "version": "1.10.41", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d" + "reference": "c6174523c2a69231df55bdc65b61655e72876d76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/93c84b5bf7669920d823631e39904d69b9c7dc5d", - "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c6174523c2a69231df55bdc65b61655e72876d76", + "reference": "c6174523c2a69231df55bdc65b61655e72876d76", "shasum": "" }, "require": { @@ -11086,7 +11086,7 @@ "type": "tidelift" } ], - "time": "2023-10-30T14:48:31+00:00" + "time": "2023-11-05T12:57:57+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index 3e894ef..1b74042 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -41,6 +41,19 @@ SkyPlugin::make() 'library' => 'Library', 'faq' => 'Faq', ]) + + // disable a Resource, if you dont use it, or want to replace them with your own resource + ->postResource() + ->pageResource() + ->faqResource() + ->libraryResource() + ->tagResource() + ->navigationResource() + + // hide a Resource, if you need to register them, but want to hide them from the sidebar navigation + ->hideResources([ + FaqResource::class, + ]) ``` ## Customize Filament Resources @@ -57,6 +70,7 @@ available resources: - FaqResource, - LibraryResource, +- NavigationResource, - PageResource, - PostResource, - TagResource, diff --git a/src/Configuration.php b/src/Configuration.php index 295d5f8..09ccb85 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -106,6 +106,8 @@ trait Configuration 'faq' => 'Faq', ]; + protected array $hiddenResources = []; + /** * where to upload all files when using the file upload field */ @@ -504,4 +506,16 @@ public function getItemTypes(): array $this->itemTypes ); } + + public function hiddenResources(): array + { + return $this->hiddenResources; + } + + public function hideResources(array $resources = []): static + { + $this->hiddenResources = $resources; + + return $this; + } } diff --git a/src/Filament/Resources/NavigationResource.php b/src/Filament/Resources/NavigationResource.php index 29ea60e..7c9b7ff 100644 --- a/src/Filament/Resources/NavigationResource.php +++ b/src/Filament/Resources/NavigationResource.php @@ -10,7 +10,6 @@ use Filament\Forms\Components\ViewField; use Filament\Forms\Form; use Filament\Forms\Set; -use Filament\Resources\Resource; use Filament\Tables\Actions\DeleteAction; use Filament\Tables\Actions\EditAction; use Filament\Tables\Columns\TextColumn; @@ -20,17 +19,13 @@ use LaraZeus\Sky\Models\Navigation; use LaraZeus\Sky\SkyPlugin; -class NavigationResource extends Resource +class NavigationResource extends SkyResource { - protected static ?string $navigationIcon = 'heroicon-o-bars-3'; + protected static ?string $navigationIcon = 'heroicon-o-queue-list'; - protected static bool $showTimestamps = true; - - private static ?string $workNavigationLabel = null; + protected static ?int $navigationSort = 99; - private static ?string $workPluralLabel = null; - - private static ?string $workLabel = null; + protected static bool $showTimestamps = true; public static function disableTimestamps(bool $condition = true): void { @@ -89,34 +84,19 @@ public static function form(Form $form): Form ->columns(12); } - public static function navigationLabel(?string $string): void - { - self::$workNavigationLabel = $string; - } - - public static function pluralLabel(?string $string): void + public static function getLabel(): string { - self::$workPluralLabel = $string; + return __('Navigation'); } - public static function label(?string $string): void + public static function getPluralLabel(): string { - self::$workLabel = $string; + return __('Navigations'); } public static function getNavigationLabel(): string { - return self::$workNavigationLabel ?? parent::getNavigationLabel(); - } - - public static function getModelLabel(): string - { - return self::$workLabel ?? parent::getModelLabel(); - } - - public static function getPluralModelLabel(): string - { - return self::$workPluralLabel ?? parent::getPluralModelLabel(); + return __('Navigations'); } public static function table(Table $table): Table diff --git a/src/Filament/Resources/SkyResource.php b/src/Filament/Resources/SkyResource.php index 8fdeb0d..e01c4fe 100644 --- a/src/Filament/Resources/SkyResource.php +++ b/src/Filament/Resources/SkyResource.php @@ -15,6 +15,11 @@ public static function getNavigationGroup(): ?string return SkyPlugin::get()->getNavigationGroupLabel(); } + public static function shouldRegisterNavigation(): bool + { + return ! in_array(static::class, SkyPlugin::get()->hiddenResources()); + } + public static function getNavigationBadge(): ?string { return (string) static::getModel()::query()->count(); diff --git a/src/SkyServiceProvider.php b/src/SkyServiceProvider.php index a3df639..16bb8bc 100644 --- a/src/SkyServiceProvider.php +++ b/src/SkyServiceProvider.php @@ -9,7 +9,6 @@ use LaraZeus\Sky\Console\migrateCommand; use LaraZeus\Sky\Console\PublishCommand; use LaraZeus\Sky\Console\ZeusEditorCommand; -use LaraZeus\Sky\Filament\Resources\NavigationResource; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -71,13 +70,6 @@ private function bootFilamentNavigation(): void return; } - NavigationResource::navigationGroup(SkyPlugin::get()->getNavigationGroupLabel()); - NavigationResource::navigationSort(999); - NavigationResource::navigationIcon('heroicon-o-queue-list'); - NavigationResource::navigationLabel(__('Navigations')); - NavigationResource::pluralLabel(__('Navigations')); - NavigationResource::label(__('Navigation')); - SkyPlugin::get() ->itemType( __('Post link'),