ryangjchandler / filament-navigation

Build structured navigation menus in Filament.
MIT License
162 stars 61 forks source link

Registering new types does not work when using "laravel/octane" #52

Closed BelyaevAD closed 1 year ago

BelyaevAD commented 1 year ago

Hello, @ryangjchandler

Registering new types "FilamentNavigation::addItemType()" does not work through AppServiceProvider when using "laravel/octane" and roadrunner

ryangjchandler commented 1 year ago

@BelyaevAD Are you on the latest version?

BelyaevAD commented 1 year ago

Yes, all packages have latest version. image

Tried doing the following steps: sail composer install sail composer run-script post-autoload-dump sail composer run-script post-update-cmd sail artisan optimize:clear sail artisan octane:reload

I use sail+octane+roadrunner in production.

And it works correctly through tinker: image

Maybe the problem is this: https://github.com/livewire/livewire/pull/3987

ryangjchandler commented 1 year ago

Hm, that shouldn't be a problem. The singleton is bound as a scoped singleton meaning it only lasts as long as a single request, even inside of Octane...

BelyaevAD commented 1 year ago

To work properly, you need to use Filament::serving

I recommend adding this to the documentation.

Example:

add in App\Providers\AppServiceProvider:

    public function boot()
    {
        Filament::serving(function () {
            FilamentNavigation::addItemType('Routes', [
                Select::make('route')
                    ->searchable()
                    ->options(function () {
                        return Helper::routeList();
                    }),
                TextInput::make('params')->label('explode params by separator "|" '),
            ]);

            FilamentNavigation::addItemType('BlogCategories', [
                Select::make('list')
                    ->multiple()
                    ->options(function () {
                        return Helper::blogCategories();
                    }),
            ]);
        });
    }
ryangjchandler commented 1 year ago

Feel free to open a PR!