Filament::getCurrentPanel() always returns true
I am writing a policy to prevent the challenger from editing the duel once he has created it. Here is the controller code:
Solution:Jump to solution
Since you’re not checking against the panelId anyway maybe Filament::isServing() works for you.
7 Replies
However it seems the user is able to access the route no matter what. Here is the policy code:
I managed to track it down to this bit of code:
Adding a bit of logging it seems even if I access the route outside the admin panel
Filament::getCurrentPanel()
always returns true. To be more specific the line Log::info('Panel: ' . Filament::getCurrentPanel()->getId());
returns admin
even if I am accessing the route itself and not in the admin panel. I can't tell if this is a bug with Filament so I am posting it here.
ThanksIs admin panel the default? If so it could be falling back to the first panel in list if no panel is currently selected. I would need to check the getCurrentPanel code to be sure.
I found this bug report https://github.com/filamentphp/filament/issues/14840 that shows others have the same issue as I do. Here a link to my repository with the Filament resources currently implemented https://bitbucket.org/ookma-kyi/ookma-kyi-core/src/main/app/Filament/Resources/. The question now is what is the workaround for the moment?
GitHub
filament()->getCurrentPanel()
always returns a panel, even outsid...Package filament/filament Package Version v3 Laravel Version v11 Livewire Version v3 PHP Version PHP 8.3 Problem description When serving a response outside of Filament, filament()->getCurrentPa...
There isn’t one, you just have to condition it correctly. Dans changed it in V4 if you want to back-port the code.
So what would be the correct condition or is backporting it the only way for now?
Solution
Since you’re not checking against the panelId anyway maybe Filament::isServing() works for you.
That seems to work for the moment and gives the desired behavior. 👍