Last active
March 14, 2023 15:34
-
-
Save sjardim/89f3db947ae03bb56660ac73c16b9064 to your computer and use it in GitHub Desktop.
A flexible front end navigation build using the Filament admin for Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\View\Composers\NavigationComposer; | |
use Filament\Forms\Components\Select; | |
use Filament\Forms\Components\TextInput; | |
use Illuminate\Support\ServiceProvider; | |
use Illuminate\Support\Facades\View; | |
use RyanChandler\FilamentNavigation\Facades\FilamentNavigation; | |
use Z3d0X\FilamentFabricator\Models\Page; | |
class ViewServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register services. | |
*/ | |
public function register(): void | |
{ | |
// | |
} | |
/** | |
* Bootstrap services. | |
*/ | |
public function boot(): void | |
{ | |
View::composer('*', NavigationComposer::class); | |
FilamentNavigation::addItemType('Link', [ | |
TextInput::make('title')->helperText('This is the text that will be displayed in the navigation menu.'), | |
TextInput::make('description'), | |
TextInput::make('url')->required(), | |
]); | |
FilamentNavigation::addItemType('Existing Page', [ | |
Select::make('page_id') | |
->label('Page') | |
->searchable() | |
->options(function () { | |
return Page::pluck('title', 'id', 'slug'); | |
}) | |
->reactive() | |
->afterStateUpdated(function (callable $set, $state) { | |
if($state) { | |
$url = Page::whereId($state)->value('slug'); | |
$set('url', $url); | |
} else { | |
$set('url', ''); | |
} | |
}), | |
TextInput::make('url') | |
->label('URL') | |
->disabled() | |
->helperText('This URL is automatically generated based on the page you select above.') | |
->hidden(fn (\Closure $get) => $get('page_id') === null), | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment