1

I want to redirect login page to home page when i already login. At the same time when I hit login route, it show me login page. I have made custom login page. Where I need to change?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291

3 Answers3

2

You should put your login route into guest middleware something like this:

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

    // Authentication Routes...
    Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');

});

and in app/Http/Middleware/RedirectIfAuthenticated.php you can define where user should be redirected in such case if you don't want to use defaults.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
0

Check Auth::user() condition in that

if(Auth::user())
//home page
else
//login page

I hope this helps you.

Shekhar Chikara
  • 3,786
  • 2
  • 29
  • 52
Niket Joshi
  • 739
  • 5
  • 23
-1

Asyou can read in the official documentation you can set a custom redirect path directly in Login- ,Register- and ResetPasswordController in App\Http\Controllers\Auth.

Simply add protected $redirectTo = 'your/custom/path'; to the top of the controller. In your case it should be the LoginController:

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    protected $redirectTo = 'your/redirect/path';

    // other stuff...
}

This should work for already logged in users as well as for not-logged-in users.

Brotzka
  • 2,959
  • 4
  • 35
  • 56