F
Filamentβ€’5mo ago
Laurens

Check if Livewire request came from Filament

I have the following macro in my AdminPanelProvider to check if requests came from Filament, this is inspired by Request::inertia() provided by Inertia.js:
Request::macro('adminPanel', fn () => Request::routeIs('filament.admin.*'));
Request::macro('adminPanel', fn () => Request::routeIs('filament.admin.*'));
This works for the default views across the panel, however the livewire.update route ofcourse doesn't fall under this. Is there a recommended approach to check if a Livewire request came from Filament? I don't feel like adding livewire.* is specific enough, since other panels or other Livewire components outside Filament would give false positives. I've looked into adding (persistent) middlewares to my panel providing adding a x-filament header myself, but these middlewares seem to run after the Livewire request. Thanks in advance!
1 Reply
Laurens
LaurensOPβ€’5mo ago
Actually, I'm using tenancy so got the idea to check if the current tenant could be retrieved during the Livewire request. This made me test out the panel helpers and this seems to work perfectly for both views and livewire requests:
Request::macro('adminPanel', function () {
return Filament::getCurrentPanel()?->getId() === 'admin';
});
Request::macro('adminPanel', function () {
return Filament::getCurrentPanel()?->getId() === 'admin';
});
This approach also doesn't rely on the filament.admin.* routing check πŸ™‚ Made it also more generic for checking the other panels while at it I guess
Request::macro('isPanel', function (string $panel) {
return Filament::getCurrentPanel()?->getId() === $panel;
});
Request::macro('isPanel', function (string $panel) {
return Filament::getCurrentPanel()?->getId() === $panel;
});
Want results from more Discord servers?
Add your server