Problem with viewAny in a FIlament Resource

Hello, i have a problem when i call the viewAny() function in a resource
public static function canViewAny(): bool
{
dd(auth()->user());
}
public static function canViewAny(): bool
{
dd(auth()->user());
}
I get null when i login to the Filament Pane as a user is there a solution to this or another way to achieve that?
6 Replies
toeknee
toeknee3w ago
It can't be null if you are logged in... Are you sure you are logged in, if you return true does the resource render as logged in? Actually it could be null on evaluation, but the actually check wouldn't be null so:
Nikos Koukos
Nikos KoukosOP3w ago
Well i am sure the user exists in my table and without this function i can loggin successfully. For example lets say i have in my table a column in the users table that is level and i do
auth()->user()->level > 30
auth()->user()->level > 30
i receive this error:
Attempt to read property "level" on null
Attempt to read property "level" on null
when i click the Log in and yes if i return true i can login successfully
toeknee
toeknee3w ago
auth()->user()?->level > 30 Does it then work as expected? user maybe null on initialisation but then on running the check it has a user object
Nikos Koukos
Nikos KoukosOP3w ago
Well it does not work because as i told you a receive that the property "level" is null and the whole auth()->user() is null
toeknee
toeknee3w ago
Correct, But does the test work correctly. i.e. if the user has a level > 30 is it true? Inverse it if need be. Do you understand the evualtion process? Vs the calling function process? Given filament needs to validate all resources/find them it evaluates them/thecode. Then it boots the applicaiton with the user.
Nikos Koukos
Nikos KoukosOP3w ago
yes if the user has a level more than 30 the it should be able to see the specific resource i am sorry can you explain me what you mean by the process you wrote ?

Did you find this page helpful?