Please forgive me if my question is too generic but I am at my wits end.
I have a users table with a level field as shown given below:
$table->unsignedSmallInteger('level')->after('password');
I want to redirect the user to different dashboards based on the value of the level field. For example for level 0 user
admindashboard
for level 1 user
userdashboard
I am using Laravel 8.4 and laravel/breeze for authentication.
Thank You
Advertisement
Answer
Ok, found a solution.
- On
routesweb.php
I have commented out the default dashboard route and created a new route for/dashboard
and pointed it toAppHttpControllersDashboardsController@index
JavaScript
x
// Route::get('/dashboard', function () {
// return view('dashboard');
// })->middleware(['auth'])->name('dashboard');
require __DIR__.'/auth.php';
Route::get('/dashboard','AppHttpControllersDashboardsController@index')->middleware(['auth'])->name('dashboard');
index
function ofDashboardsController
JavaScript
public function index() {
$data['authenticated_user'] = Auth::user();
if($data['authenticated_user']->level == 0) {
echo "Admin";
} elseif($data['authenticated_user']->level == 1) {
echo "Employee";
} else {
echo "Security";
}
}
Basically this will accomplish what I want to achieve.
Thanks