Help us understand the problem. What is going on with this article?

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';
Ioan
PHP、Laravelの初心者マン
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away