Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

protendai's avatar

Laravel 8 returning Boolean instead of field value

Good day I have a table users with name, surname,role,email etc. When i use Auth::user()->name it displays the value correctly but When i use Auth::user()->role it displays 1

All my roles are strings such as "AD" , "SEC , "HOD" but it returns 1

0 likes
6 replies
Sinnbeck's avatar

Show the user model class. Maybe you have a cast or an accessor

protendai's avatar

In short , im actually using the basic User.php model in Laravel 8 with a few added fields

protected $fillable = [ 'sap_username', 'sap_password', 'sap_database', 'sap_branch', 'name', 'surname', 'role', 'department_id', 'email', 'phone', 'status', 'first_loggin', 'password', ];

jivanrij's avatar

So you have a user.role field in your database that contains strings like 'AD' & 'SEC'?

Are you refactoring the roles? Can it be that there is some lost logic in the User model? What is the type of $user->role?

protendai's avatar

@jivanrij hi , so the roles are strings , in the db they are varchar. Im not type casting or doing any conversions on them. In my blade file im using {{ Auth::user()->role }} and its giving me 1 instead of AD or SEC ...

jivanrij's avatar

@protendai Try testing it in tinker. This way you know if it's something model related, or more something outside the model.

Please or to participate in this conversation.