auth()->user()->is_admin inside AdminPanel Provider return null

How to fix it plase ? like this method
No description
Solution:
It’s a service provider. Auth is only available after middlewares. Wrap it in a closure and it will work.
Jump to solution
8 Replies
christmex
christmex11mo ago
when u dd(auth()->user()) wht is return? the model? is that attribute for is_admin? i use the auth()->user() too in my project and it works
Solution
Dennis Koch
Dennis Koch8mo ago
It’s a service provider. Auth is only available after middlewares. Wrap it in a closure and it will work.
bhattji
bhattji5mo ago
How to wrap? Can you please give some code example? Also, I have the same issue with Session. Is it the same?
Vp
Vp5mo ago
How to wrap?
(fn() => ...)
Dennis Koch
Dennis Koch5mo ago
Session also only works after the framework if booted.
bhattji
bhattji5mo ago
Ok so this is how it works, ->visible(fn() => auth()->user()->is_admin)
Zen Nitiruj
Zen Nitiruj5mo ago
Have you set attribute is_admin for user model?
Dennis Koch
Dennis Koch5mo ago
He just said that it works 😅

Did you find this page helpful?