Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbpp's avatar
Level 3

Redirect out of login page if session alive

Hi there, in my laravel application, there is something strange happening, i had the idea when a user have a active session, some how the app didnt let the user go the the login page form. For example if im logged in to my app, and then go to login page, i expect that im redirect to the dashboard since i have a live session.

What is wrong?

My routes:

// Login and Dashboard route
Route::get('/', 'PagesController@getIndex');
Route::get('dashboard', 'MainController@getDashboard');

//Authentication Routes
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

My laravel version is 5.2

1 like
1 reply
tisuchi's avatar
tisuchi
Best Answer
Level 70

One of the easiest way that, you can wrap your login method in your controller like follows-

public function login(){

    if (Auth::check()) {
        //write your login code here...

    }
}

Don't forget you import use Auth; top of your controller.

3 likes

Please or to participate in this conversation.