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
christmex9mo 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 Koch6mo ago
It’s a service provider. Auth is only available after middlewares. Wrap it in a closure and it will work.
bhattji
bhattji3mo ago
How to wrap? Can you please give some code example? Also, I have the same issue with Session. Is it the same?
Vp
Vp3mo ago
How to wrap?
(fn() => ...)
Dennis Koch
Dennis Koch3mo ago
Session also only works after the framework if booted.
bhattji
bhattji3mo ago
Ok so this is how it works, ->visible(fn() => auth()->user()->is_admin)
Zen Nitiruj
Zen Nitiruj3mo ago
Have you set attribute is_admin for user model?
Dennis Koch
Dennis Koch3mo ago
He just said that it works 😅
Want results from more Discord servers?
Add your server