F
Filamentβ€’15mo ago
MRBUG

if user is admin

i want a functionallity where i want that if user is admin = 1 it can go to dashbaord but if is admin is 0 than he can not access the admin panel currently i am using this functionallity which is give in filamentphp documentation and i created a code in user model like this
public function canAccessPanel(Panel $panel): bool { $user = User::where('email', $this->email)->first(); if ($user && $user->is_admin === 1) { return true; } return false; }
but i also got this given image. But i want that if i can not access the admin panel it will show error in the login page and i want a error message like "you are not admin" i dont want given image result how can i archive this functionallity with custom error message if is_admin=0 this will show in admin page like "this email address is not admin /or somthing other custom error message insted of 403 forbidden message"
No description
5 Replies
ModestasV
ModestasVβ€’15mo ago
For that you might want to create custom login pages. Then you can handle all of the errors in your login action as you need πŸ™‚
MRBUG
MRBUGOPβ€’15mo ago
toeknee
toekneeβ€’15mo ago
Yep as above, just override the Filament Login page, and onLogin redirect if cannot access dashboard
MRBUG
MRBUGOPβ€’15mo ago
i think I am making a mistake can anyone describe to me how I can make a custom login for the above functionality I think i am not able to make a custom login (i don't know how to create it as well as it is given in the documentation ) can anyone help me sorry.
toeknee
toekneeβ€’15mo ago
copy: run: php artisan make:livewire Auth\Login Edit class to read: class Login extends \Filament\Http\Livewire\Auth\Login Review: \Filament\Http\Livewire\Auth\Login and override the functions you need. This would tend to be on authenticate() if not admin redirect()->url('/')
Want results from more Discord servers?
Add your server