Add auth()->user() to shouldRegisterNavigation()

How to use auth()->user() function or access authenticated user through shouldRegisterNavigation() function ? :
public static function shouldRegisterNavigation(array $parameters = []): bool
{
return false;
}
public static function shouldRegisterNavigation(array $parameters = []): bool
{
return false;
}
2 Replies
Dennis Koch
Dennis Koch12mo ago
What do you mean? Did you try to just add that code? Anything not working?!
DrByte
DrByte12mo ago
In my Pages I do it with various logic, depending on the need. Here are 2 examples. (Note that 'admin' here is a custom guard, and you may not want/need it, just use auth() instead.):
public static function shouldRegisterNavigation(): bool
{
return auth('admin')->user()->hasRole(['Super-Admin']);
}
public static function shouldRegisterNavigation(): bool
{
return auth('admin')->user()->hasRole(['Super-Admin']);
}
public static function shouldRegisterNavigation(): bool
{
return filament()->auth()->user()->email === '[email protected]';
}
public static function shouldRegisterNavigation(): bool
{
return filament()->auth()->user()->email === '[email protected]';
}
Want results from more Discord servers?
Add your server