Laravel 5 redirects to homepage if trying to go to login screen

I have a login screen, which is the base URL (www.mysite.com/).

When a user logs in, they are redirected to their home page (/ home).

But they can still return to the login page if they go to the root directory.

How can I make registered users be sent to their home page if they are logged in (unless, of course, they see the login page)?

+7
source share
5 answers

I did this on my router, although I'm not sure if this is the best solution:

Route::get('/', function () {
    if(Auth::check()) {
        return redirect('/dashboard');
    } else {
        return view('auth.login');
    }
});
+6

.

Laravel 5 "" , , :

Route::get('/', ['middleware' =>'guest', function(){
  return view('auth.login');
}]);

App\Http\Middleware\RedirectIfAuthenticated , .

/home.

+4

, /home URI, . , redirectPath AuthController:

AuthController redirectPath

protected $redirectPath = '/dashboard';

http://laravel.com/docs/5.1/authentication#Authenticating

+2
source

In my case, I had to delete cookies in my browser in order to fix the / login redirects.

+2
source

In my case, I edited the HomeController construct as shown below and worked:

  public function __construct()
  {
    $this->middleware('auth')->except('index');
  }
0
source

Source: https://habr.com/ru/post/1606156/


All Articles