That throws an error that the function does not exist. I tried the original (Auth:user()->role->name) in an existing application and there it works just fine. (with another relation because I don't have a roles table there.
You should make sure you are authenticated before using Auth::user().
if(Auth::check())
{
$role = Auth::user()->role->name;
}
codingjames liked this reply
Ok I found out why it wasn't working for me. The thing is that my User model where I was talking about was a part of my package, and because Laravel has it's own User model in the default Laravel installation it was not working.
Your package model does not override an already existing model. I solved my problem by making a Trait instead of a model for my package.
codingjames liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community