How to get currently logged user in AppPanelProvider?

In AppPanelProvider::panel() I have $user = Auth::user();, but the result is NULL i.e. it seems that the currently logged user is not available in this method. Is there a way to have access to it in this method?
6 Replies
nielsdscrd
nielsdscrd16mo ago
In AppPanelProvider::panel() you are defining the middleware to be run, including authentication and sessions. Hence at that point the user cannot be known yet.
StanProg
StanProgOP16mo ago
I'm defining there the UserMenu, which depends on the currently logged user. Is there a way to setup the UserMenu on another place?
manojkiran
manojkiran16mo ago
I haven't started using filament v3 yet so. Does AppPanelProvider extends Filament\PanelProvider ?
manojkiran
manojkiran16mo ago
If yes it's not possible to get the current user you can read more from here https://stackoverflow.com/questions/37372357/laravel-how-to-get-current-user-in-appserviceprovider
Stack Overflow
Laravel - How to get current user in AppServiceProvider
So I am usually getting the current user using Auth::user() and when I am determining if a user is actually logged in Auth::check. However this doesn't seem to work in my AppServiceProvider. I am u...
StanProg
StanProgOP16mo ago
Is there another way to have a UserMenu with elements based on the currently logged User? For the reference, I did it with closure on hidden():
$userMenuItems[] = MenuItem::make()
->label(__('pages/org.title'))
->url(function() {
return Org::getUrl();
})
->hidden(function() {
return !Auth::user()->hasDirectPermission('manage org');
})
->icon('heroicon-m-building-office');
$userMenuItems[] = MenuItem::make()
->label(__('pages/org.title'))
->url(function() {
return Org::getUrl();
})
->hidden(function() {
return !Auth::user()->hasDirectPermission('manage org');
})
->icon('heroicon-m-building-office');
manojkiran
manojkiran16mo ago
is it possible to do this in middleware ? and I think You can access the Gate facade in service provider
Want results from more Discord servers?
Add your server