0

How can I load different controllers based on user logged in or not?

What I'm trying to do is:

// in app/Http/routes.php

Route::get('/', [
    'uses' => 'App\Http\Controllers\HomeController@index',
]);


// modules/Lesson/Http/routes.ph

Route::group(['middleware' => 'auth'], function () {

    Route::get('/', [
        'uses' => 'Modules\Lesson\Http\Controllers\DashboardController@index',
    ]);
});

So when user logged in, it shows DashboardController@index, otherwise HomeController@index

But it always loading /login form when user not signed in.

Is there any way to achieve this?

I have seen following link Laravel 5 Entrust one route - load different controller based on Role. But I can't do like that since module is optional.

Community
  • 1
  • 1
Sankaran
  • 1
  • 2

0 Answers0