Login user based on Department Panel

Hello Everyone I hope you're all doing well. I'm currently working on a project and could use some guidance and expertise to help me implement a user registration system with department-based access. I have three different panels: 'hr', 'finance', and 'property,' each with its respective logins. My goal is to allow a superadmin to register new users with their email, password, and department. When a registered user logs in, they should be directed to their designated department panel.
Solution:
I figured it out already Thankyou very much...
Jump to solution
12 Replies
tuto1902
tuto1902•14mo ago
Unfortunately I haven't found a suitable solution for this. I might have to post a question in the official discord server because this goes beyond my knowledge. I imagine it has something to do with the Authentication middleware used internally but I still haven't figure out how to redirect the user on login.
sadiqgoni13
sadiqgoni13OP•14mo ago
Wow this is massive, Thankyou for having a time to check it out. Do you think I should wait for you to get the response from the officials, or if you can help with an alternative way or method ?
einnlleinhatt_
einnlleinhatt_•14mo ago
What about using viewAny() ?
sadiqgoni13
sadiqgoni13OP•14mo ago
Please can you guide through based on your understanding
sadiqgoni13
sadiqgoni13OP•14mo ago
I got this answer but I doesn't seem to understand the logic
No description
einnlleinhatt_
einnlleinhatt_•14mo ago
My bad it's redirect, maybe something like this
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteDepartmentServiceProvider::FINANCE);
}
}

return $next($request);
}
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteDepartmentServiceProvider::FINANCE);
}
}

return $next($request);
}
Also how do you separate the user role in database ?
sadiqgoni13
sadiqgoni13OP•14mo ago
I have the admin panel who is responsible in registering a new user with email , password and then department ( hr == 1, finance == 2 , property == 3) Great let me implement the logic
einnlleinhatt_
einnlleinhatt_•14mo ago
@sadiqgoni13 or you can create a new middleware and verify the user is finance or hr And inside the hr panel add the VerifyIsHr middleware class in it 🤔
sadiqgoni13
sadiqgoni13OP•14mo ago
Okay I will do that
einnlleinhatt_
einnlleinhatt_•14mo ago
I forgot how to check the user role if 1 or 2 but i would do this maybe
public function handle(Request $request, Closure $next): Response
{
if (Auth::user() && Auth::user()->is_hr) {
return redirect('/hrpanel');
}
}
public function handle(Request $request, Closure $next): Response
{
if (Auth::user() && Auth::user()->is_hr) {
return redirect('/hrpanel');
}
}
And inside the panel i will add this
->middleware([
VerifyIsHr::class
->middleware([
VerifyIsHr::class
@sadiqgoni13did you get it to work ?
einnlleinhatt_
einnlleinhatt_•14mo ago
If not maybe you can use this plugin i just found out https://filamentphp.com/plugins/shane-rosenthal-panel-roles
Filament
Panel Roles by Shane D Rosenthal - Filament
Filament Panel Roles is an intuitive way to ensure all users of a specified panel within Filament v3 is assigned a role during registration and has a specified role using Laravel Middleware.
Solution
sadiqgoni13
sadiqgoni13•14mo ago
I figured it out already Thankyou very much
Want results from more Discord servers?
Add your server