auth()->user()->is_admin inside AdminPanel Provider return null
How to fix it plase ? like this method
Solution:Jump to solution
It’s a service provider. Auth is only available after middlewares. Wrap it in a closure and it will work.
8 Replies
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
It’s a service provider. Auth is only available after middlewares. Wrap it in a closure and it will work.
How to wrap?
Can you please give some code example?
Also, I have the same issue with Session. Is it the same?
How to wrap?
(fn() => ...)
Session also only works after the framework if booted.
Ok so this is how it works,
->visible(fn() => auth()->user()->is_admin)
Have you set attribute is_admin for user model?
He just said that it works 😅