目的
- Auth認証を行っていないと表示できないページを実装する方法をまとめる
方法
- ルーティングに記載するだけで実装が可能である。
-
下記のようなルーティング情報が記載されていたとする。
アプリ名ディレクトリ/routes/web.phpRoute::get('/top', [TopController::class, 'index'])->name('top.index');
-
下記のように記載することで当該ページが認証していないと表示できないページにする事ができる。
アプリ名ディレクトリ/routes/web.phpRoute::get('/top', [TopController::class, 'index'])->middleware(['auth'])->name('top.index');