I have a isAdmin() which return true if exist record. I have 2 where condition. I first I check if role is Admin and second where check if id is user logged id. And my problem is how I check to second where id currently logged id user.
model
I have a isAdmin() which return true if exist record. I have 2 where condition. I first I check if role is Admin and second where check if id is user logged id. And my problem is how I check to second where id currently logged id user.
model
2
Answers
Laravel has an
Auth
facade that can help retrieve user details. So basically add it to the top of your file then call it as such:Although it is much better to do this in your controller instead.
To use anywhere like this:
You can update the
isAdmin()
function in yourUser
model like this:This will give you whether the logged in user has the
Admin
role.