LoginSignup
35
24

More than 3 years have passed since last update.

Laravel ログイン中、ログイン画面にアクセスした際のリダイレクト先変更

Last updated at Posted at 2018-03-08

最初に

php artisan make:auth で作成した認証機能である
変更箇所のみ記載、説明なし

目的

  • ログイン後に/homeでなく、/topにリダイレクトしたい
  • ログイン中に/loginにアクセスした際、/topにリダイレクトしたい

app\Http\Middleware\RedirectIfAuthenticated.phpの変更


    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
-            return redirect('/home');
+            return redirect('/top');
        }

        return $next($request);
    }

app\Http\Controllers\Auth\LoginController.phpの変更

-    protected $redirectTo = '/home';
+    protected $redirectTo = '/top';

その他の変更

  • app\Http\Controllers\Auth\RegisterController.php
  • app\Http\Controllers\Auth\ResetPasswordController.php
-    protected $redirectTo = '/home';
+    protected $redirectTo = '/top';
35
24
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
24