I’m working on a Laravel application and using the Filament admin panel. I created a custom helper function to check user roles and access, but when I call auth()->user() inside this helper function, it returns null. Here is the code for my custom helper function:
<code> function checkUserRole()
{
$user = auth()->user();
if ($user && $user->role == 'admin') {
return true;
}
return false;
}
}
</code>
<code> function checkUserRole()
{
$user = auth()->user();
if ($user && $user->role == 'admin') {
return true;
}
return false;
}
}
</code>
function checkUserRole()
{
$user = auth()->user();
if ($user && $user->role == 'admin') {
return true;
}
return false;
}
}
Additional Context:
- I’m using Laravel 8.
- Filament admin panel is being used for the admin
interface. - The custom helper function is defined in a file that is
included in the composer.json autoload section.