LoginSignup
6
3

More than 3 years have passed since last update.

【Laravel】Route [login] not defined. を解決する

Last updated at Posted at 2020-03-09

環境

  • Laravel Framework 6.14.0

エラーメッセージ


Symfony\Component\Routing\Exception\RouteNotFoundException
Route [login] not defined.

経緯

未認証のユーザを弾くため、コントローラに以下のコードを追加したらエラーが発生した。
名前付きルートloginが存在しないと怒られている。

Http/Controllers/HogeController.php

public function __construct(){
    $this->middleware('auth');
}

解決法

未認証のユーザはトップページに飛ばしたかったので、トップページへのgetに名前を付けました。

routes/web.php

Route::get('/', function () {
    return view('index');
})->name('login');
6
3
0

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
6
3