質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.30%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

解決済

1回答

1085閲覧

キャッシュをクリアしてもAuth guard [] is not definedを解決できない

aiueo-hiragana

総合スコア15

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2022/08/26 14:30

前提

Larvel8系で認証をしようとしており、
https://readouble.com/laravel/5.8/ja/api-authentication.html
を参考に標準認証?を実装しています

postmanで実行したところ認証は通っていますがトップページが表示されません。
イメージ説明
config:clear config:cacheを実行しても変わりませんでした。

発生している問題・エラーメッセージ

InvalidArgumentException Auth guard [] is not defined.

該当のソースコード

php

1<?php 2// web.php 3use Illuminate\Support\Facades\Route; 4use Symfony\Component\HttpFoundation\Request; 5use App\Http\Controllers\ItemController; 6use App\Http\Controllers\VideoController; 7use Illuminate\Support\Facades\Auth; 8 9/* 10|-------------------------------------------------------------------------- 11| Web Routes 12|-------------------------------------------------------------------------- 13| 14| Here is where you can register web routes for your application. These 15| routes are loaded by the RouteServiceProvider within a group which 16| contains the "web" middleware group. Now create something great! 17| 18*/ 19 20Auth::routes(); 21Route::group(['middleware' => 'auth'], function () { 22 Route::get('/', [App\Http\Controllers\ItemController::class, 'index'])->name('index'); 23}); 24

php

1<?php 2// api.php 3use Illuminate\Http\Request; 4use Illuminate\Support\Facades\Route; 5use App\Http\Controllers\Api\AuthController; 6use App\Http\Controllers\Api\VideoApiController; 7 8/* 9|-------------------------------------------------------------------------- 10| API Routes 11|-------------------------------------------------------------------------- 12| 13| Here is where you can register API routes for your application. These 14| routes are loaded by the RouteServiceProvider within a group which 15| is assigned the "api" middleware group. Enjoy building your API! 16| 17*/ 18 19Route::middleware('auth:api')->get('/user', function (Request $request) { 20 return $request->user(); 21});

php

1<?php 2// config/auth.php 3return [ 4 5 /* 6 |-------------------------------------------------------------------------- 7 | Authentication Defaults 8 |-------------------------------------------------------------------------- 9 | 10 | This option controls the default authentication "guard" and password 11 | reset options for your application. You may change these defaults 12 | as required, but they're a perfect start for most applications. 13 | 14 */ 15 16 'defaults' => [ 17 'web' => [ 18 'driver' => 'session', 19 'provider' => 'users', 20 ], 21 ], 22 23 /* 24 |-------------------------------------------------------------------------- 25 | Authentication Guards 26 |-------------------------------------------------------------------------- 27 | 28 | Next, you may define every authentication guard for your application. 29 | Of course, a great default configuration has been defined for you 30 | here which uses session storage and the Eloquent user provider. 31 | 32 | All authentication drivers have a user provider. This defines how the 33 | users are actually retrieved out of your database or other storage 34 | mechanisms used by this application to persist your user's data. 35 | 36 | Supported: "session" 37 | 38 */ 39 40 'guards' => [ 41 'web' => [ 42 'driver' => 'session', 43 'provider' => 'users', 44 ], 45 46 'api' => [ 47 'driver' => 'token', 48 'provider' => 'users', 49 'hash' => false, 50 ], 51 ], 52 53 /* 54 |-------------------------------------------------------------------------- 55 | User Providers 56 |-------------------------------------------------------------------------- 57 | 58 | All authentication drivers have a user provider. This defines how the 59 | users are actually retrieved out of your database or other storage 60 | mechanisms used by this application to persist your user's data. 61 | 62 | If you have multiple user tables or models you may configure multiple 63 | sources which represent each model / table. These sources may then 64 | be assigned to any extra authentication guards you have defined. 65 | 66 | Supported: "database", "eloquent" 67 | 68 */ 69 70 'providers' => [ 71 'users' => [ 72 'driver' => 'eloquent', 73 'model' => App\Models\User::class, 74 ], 75 76 // 'users' => [ 77 // 'driver' => 'database', 78 // 'table' => 'users', 79 // ], 80 ], 81 82 /* 83 |-------------------------------------------------------------------------- 84 | Resetting Passwords 85 |-------------------------------------------------------------------------- 86 | 87 | You may specify multiple password reset configurations if you have more 88 | than one user table or model in the application and you want to have 89 | separate password reset settings based on the specific user types. 90 | 91 | The expire time is the number of minutes that each reset token will be 92 | considered valid. This security feature keeps tokens short-lived so 93 | they have less time to be guessed. You may change this as needed. 94 | 95 */ 96 97 'passwords' => [ 98 'users' => [ 99 'provider' => 'users', 100 'table' => 'password_resets', 101 'expire' => 60, 102 'throttle' => 60, 103 ], 104 ], 105 106 /* 107 |-------------------------------------------------------------------------- 108 | Password Confirmation Timeout 109 |-------------------------------------------------------------------------- 110 | 111 | Here you may define the amount of seconds before a password confirmation 112 | times out and the user is prompted to re-enter their password via the 113 | confirmation screen. By default, the timeout lasts for three hours. 114 | 115 */ 116 117 'password_timeout' => 10800, 118 119]; 120

補足情報(FW/ツールのバージョンなど)

Laravel version 8.83.23
PHP version 8.1.9

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

php

1Route::group(['middleware' => 'auth:web'], function () { 2 Route::get('/', [App\Http\Controllers\ItemController::class, 'index'])->name('index'); 3});

webを付け忘れているだけでした。

投稿2022/08/26 14:41

aiueo-hiragana

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問