0
votes

I am trying to have the same route homepage / but different controllers for auth and guest users but i am unable to do this. I have searched and tried all the results on google, stackoverflow etc, none have worked. I am guessing it is because of the version i am using Laravel Framework 7.15

 $uses = 'BlogController@index';
 if (!is_null(auth()->user())) {
     $uses = 'HomeController@index';

 }
 Route::get('/', $uses);

BlogController is for guest and HomeController is for authenticated users. So when i run the code for authenticated users it shows only shows the Blog(guest) homepage and not users HomeController page. Thanks for your help in advance.

1

1 Answers

1
votes

You can try this.

Route::get('/', (function() {
    return auth()->user()
        ? app()->make(\App\Http\Controllers\HomeController::class)->index()
        : app()->make(\App\Http\Controllers\BlogController::class)->index();
}));