ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
| この記事の要点 |
|---|
|
エラーの状況
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
# または
The POST method is not supported for this route. Supported methods: GET, HEAD.
Laravel が「このルートはそのメソッドでは呼べない」と判断したエラー。HTTP 仕様としては 405 Method Not Allowed。
主な原因と対処
原因 1: フォームの method 属性が違う
// routes/web.php
Route::post('/users', [UserController::class, 'store']);
原因 2: PUT/PATCH/DELETE で @method 忘れ
HTML フォームは GET / POST しか直接送信できない。PUT/PATCH/DELETE はPOST + _method パラメータで送信する必要がある:
// routes/web.php
Route::put('/users/{id}', [UserController::class, 'update']);
Route::delete('/users/{id}', [UserController::class, 'destroy']);
原因 3: Route::get と Route::post の登録ミス
// ダメな例
Route::get('/users/store', [UserController::class, 'store']); // POST にすべき
// フォームから POST で送信
// → GET ルートしかないので 405
// 修正
Route::post('/users', [UserController::class, 'store'])->name('users.store');
原因 4: Resource Controller の HTTP メソッド忘れ
// Route::resource はモダンな REST 慣習に従う
Route::resource('users', UserController::class);
// 生成されるルート:
// GET /users → index
// GET /users/create → create
// POST /users → store
// GET /users/{id} → show
// GET /users/{id}/edit → edit
// PUT /users/{id} → update ← PUT
// PATCH /users/{id} → update ← PATCH
// DELETE /users/{id} → destroy ← DELETE
// 確認
// $ php artisan route:list
原因 5: Ajax / fetch のメソッド指定漏れ
// ダメな例
fetch("/api/users/1", {
body: JSON.stringify({ name: "Alice" })
// method 指定なし → デフォルト GET
});
// route が PUT なら 405
// 修正
fetch("/api/users/1", {
method: "PUT",
headers: {
"Content-Type": "application/json",
"X-CSRF-TOKEN": csrfToken
},
body: JSON.stringify({ name: "Alice" })
});
// axios
axios.put("/api/users/1", { name: "Alice" });
axios.patch("/api/users/1", { status: "active" });
axios.delete("/api/users/1");
原因 6: api.php と web.php の区別
// routes/api.php (URL prefix: /api)
Route::post('/users', [UserController::class, 'store']);
// routes/web.php
Route::post('/users', [UserController::class, 'store']);
// /api/users と /users は別のルート
// クライアントから誤って /api/users にリクエストして /users と認識される逆もあり
route:list で確認
# 全ルート一覧
$ php artisan route:list
GET|HEAD / home.index
GET|HEAD users users.index
POST users users.store
GET|HEAD users/create users.create
GET|HEAD users/{id} users.show
GET|HEAD users/{id}/edit users.edit
PUT|PATCH users/{id} users.update
DELETE users/{id} users.destroy
# 特定のパスで絞り込み
$ php artisan route:list --path=users
# 特定の HTTP メソッド
$ php artisan route:list --method=POST
レスポンスヘッダで許可メソッド確認
$ curl -I -X GET http://localhost/users/1
HTTP/1.1 405 Method Not Allowed
Allow: PUT, PATCH, DELETE ← 許可されているメソッド
API でカスタムエラーレスポンス
// app/Exceptions/Handler.php
public function render($request, Throwable $exception)
{
if ($exception instanceof MethodNotAllowedHttpException) {
return response()->json([
'error' => 'method_not_allowed',
'message' => 'このリソースに対する HTTP メソッドが正しくありません',
'allowed_methods' => $exception->getHeaders()['Allow'] ?? '',
], 405);
}
return parent::render($request, $exception);
}
関連エラー
| エラー | 意味 |
|---|---|
NotFoundHttpException (404) | ルート自体が存在しない |
MethodNotAllowedHttpException (405) | このページのエラー |
TokenMismatchException (419) | CSRF トークン不一致 |
AuthorizationException (403) | 権限不足 |
ValidationException (422) | バリデーション失敗 |
関連記事
ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
子ページ
子ページはありません
同階層のページ
- SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost'
- Add [~] to fillable property to allow mass assignment on [App\~].
- PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in ~
- Changing columns for table "~" requires Doctrine DBAL; install "doctrine/dbal"
- MethodNotAllowedHttpException No message
- Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found
- production.ERROR: No application encryption key has been specified.
- Dotenv values containing spaces must be surrounded by quotes.
- Laravel \ Socialite \ Two \ InvalidStateException
- The page has expired due to inactivity. Please refresh and try again.
- Failed to clone https://github.com/symfony/thanks.git via https, ssh protocol
- Illegal offset type
- Cannot access protected property Illuminate\Http\Request::$...
- Emitted value instead of an instance of Error
- 画像保存時にInternal Server Error
- Failed to authenticate on SMTP server with username ...
- PostTooLargeException
- Database hosts array is empty.
- Invalid request (Unsupported SSL request)
- does not comply with psr-4 autoloading standard. Skipping.
- MySQLのSTR_TO_DATE関数を使用するとnullが返却される問題
人気ページ
- 1 Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法
- 2 tomcat の起動 / 停止ログと catalina.log・catalina.out の違い
- 3 JavaScript base URL 取得方法|window.location.origin と SSR/Node.js 対応
- 4 YouTube Data API v3 エラー一覧|403/400/404 の主要原因と切り分け
- 5 Spring Frameworkのアノテーション一覧
- 6 Laravel エラー一覧|500/Blade/DB 接続/ルーティングの代表エラー
- 7 3Dグラフィックスとは|モデリング/レンダリング/主要ソフトウェア (Blender / Maya)
- 8 【Spring】@Valueアノテーションとは
- 9 CATALINA_HOME の確認方法 (Linux / Mac)
- 10 【Spring】@Autowiredアノテーションとは
最近更新/作成されたページ
- Laravel キャッシュクリア完全ガイド(cache:clear / config:clear / 2026-05-18 07:42:07
- プロジェクトの作成と削除 2026-05-18 07:42:07
- インストール直後にNetbeansが反応しない 2026-05-18 07:42:07
- 動画やチャンネルの検索 2026-05-18 07:42:07
- APIキー取得方法 2026-05-18 07:42:07
- チャンネル情報の取得 2026-05-18 07:42:07
- API 入門 — Web API(REST / GraphQL / gRPC / 2026-05-18 07:42:07
- インストール(eclipseプラグイン) 2026-05-18 07:42:07
- Laravel「Dotenv values containing spaces must be surrounded 2026-05-18 07:42:07
- エラー一覧 2026-05-18 07:42:07
- curl: (51) SSL: certificate subject name '~' does not match 2026-05-18 07:42:07
- インストール方法(Windows版) 2026-05-18 07:42:07
- JSONから配列に変換 2026-05-18 07:42:07
- 処理を一定時間待つ 2026-05-18 07:42:07
- A non well formed numeric value encountered 2026-05-18 07:42:07
コメントを削除してもよろしいでしょうか?