LoginSignup
23

More than 3 years have passed since last update.

posted at

updated at

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

最初に

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';

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
What you can do with signing up
23