Filament Shield
In my app, all of users give me bool '1' mean {{ auth()->user()->isSuperAdmin() }}. Here is code.
User.php
20 Replies
When you echo a bool it goes to 1 or 0
it wont echo to 'true'
1
you need to var_dump() to get the try var value and explanation. echoing a bool returns an integer
this user isn't superadmin
@dump(auth()->user()->isSuperAdmin())
What does it give?
it's true
So that code you are using is checking if the current user logged in is a superAdmin(). It's saying they are, if that's true then your issue is either 1. Your SuperAdmin function. Or two, you are expecting that code to check the record and not the logged in user currently viewing.
How can I solve that? 🥹
Should the function be checking the logged in user viewing the resource/
like that?
You still haven't answered my question
@shaungbhone what do you want to achieve exactly?
Do you want to show something for example a badge if the user is a super-admin?
Yes sure
yes
Just return:
return auth()
->user()
->hasRole('super_admin');
Which should check the current user has the role super_admin assigned to them
I want to be sure my function
isSuperAdmin()
is correct or not!So you need to check / test that then.
Please this is basic php/laravel stuff with spatie permissions / roles. Not really filament related.
Ok thank you I'll check it out.