0

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

\admin\dashboard

for level 1 user

\user\dashboard

I am using Laravel 8.4 and laravel/breeze for authentication.

Thank You

Debajeet Choudhury
  • 389
  • 2
  • 5
  • 9

1 Answers1

0

Ok, found a solution.

  1. On routes\web.php I have commented out the default dashboard route and created a new route for /dashboard and pointed it to App\Http\Controllers\DashboardsController@index
// Route::get('/dashboard', function () {
//     return view('dashboard');
// })->middleware(['auth'])->name('dashboard');

require __DIR__.'/auth.php';

Route::get('/dashboard','App\Http\Controllers\DashboardsController@index')->middleware(['auth'])->name('dashboard');
  1. index function of DashboardsController
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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Debajeet Choudhury
  • 389
  • 2
  • 5
  • 9