I am working on a Laravel project where I have three types of admins, each with their own login pages. Here are the routes:
// Core Admin Routes
Route::get('/core-admin', [CoreAuthController::class, 'loadLogin']);
Route::post('/core-admin', [CoreAuthController::class, 'login'])->name('login');
Route::middleware('auth')->group(function () {
Route::get('/core-admin/dashboard', [CoreAuthController::class, 'coreAdmin']);
Route::get('/core-admin/logout', [CoreAuthController::class, 'logout']); // Change logout route
});
// Master Admin Routes
Route::get('/master-admin', [MasterAuthController::class, 'loadLogin']);
Route::post('/master-admin', [MasterAuthController::class, 'login'])->name('login');
Route::middleware('auth')->group(function () {
Route::get('/master-admin/dashboard', [MasterAuthController::class, 'masterAdmin']);
Route::get('/master-admin/logout', [MasterAuthController::class, 'logout']); // Change logout route
});
// Website Admin Routes
Route::get('/website-admin', [WebsiteAuthController::class, 'loadLogin']);
Route::post('/website-admin', [WebsiteAuthController::class, 'login'])->name('login');
Route::middleware('auth')->group(function () {
Route::get('/website-admin/dashboard', [WebsiteAuthController::class, 'websiteAdmin']);
Route::get('/website-admin/logout', [WebsiteAuthController::class, 'logout']); // Change logout route
});
The issue I’m facing is that when I log in as a core-admin, I’m redirected to the website-admin/dashboard. I’ve checked my controller code and it seems fine, so I suspect the issue lies within the route files. Interestingly, if I comment out the route code for the website-admin, I’m then redirected to the master-admin/dashboard. Any insights on what could be causing this?
2
Answers
i think you should provide more details especially regarding your auth middleware , im gonna provide you with an example on how to manage multi role using breeze in laravel
first start by creating the role middleware in
/app/Http/Midlleware
Then register the middleware
add this code to
bootstrap/app
Then add this function to your user model
to specify the redirect route of each user based on there role
finally modify your route file
I think you need to change the order. I’ve had a similar problem before. You should try to change the order like this.
// Master Admin Routes
// Website Admin Routes
// Core Admin Routes