0
votes

I have web app by Laravel ,I want to make routing depend on login status inside web.php file for a reason. i make this :

Route::get('/', function () {
    if (!Auth::guest()){
        return ???????
    }
    
else {
    return view('welcome');
}

I want to return route named "home" , How can I do that ?

3
i think you need to use `middleware for this sinario - Kamlesh Paul
You better have a auth middleware? - nice_dev
can I do it without middleware? - SM_Berwari

3 Answers

1
votes

If the routes exists, then this should work.

Route::get('/', function() {
   return (!Auth::guest()) view('home') : view("welcome");
});
1
votes
Route::group(['middleware' => ['auth', 'is_admin']], function () {
    Route::get('/dashboard', function () {
        return view('home');
    });
});
0
votes

I using middleware for all my routes if need ,but for a reason I need to do this ,I did this and solved ,this if I don't have argument to pass:

Route::get('/', function () {
    if (!Auth::guest()){
        return view('home');
    }
    
else {
    return view('welcome');
}