ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子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アノテーションとは
最近更新/作成されたページ
- IPv6とは|128bitアドレス・コロン16進表記/::省略・リンクローカル・SLAAC・デュアルスタック NEW 2026-06-22 12:34:44
- MAC アドレスフィルタリングの仕組みと限界 | ネットワーク入門 NEW 2026-06-22 12:19:10
- VPNとは|暗号トンネル・サイト間/リモートアクセス・IPsec/SSL-VPN/WireGuardを解説 NEW 2026-06-22 12:19:10
- WebSocket とは 全二重リアルタイム通信 ws/wss | ネットワーク入門 NEW 2026-06-22 12:17:25
- HTTP/2 とは 多重化・HPACK・バイナリフレーム | ネットワーク入門 NEW 2026-06-22 12:17:25
- Web通信プロトコル入門 HTTP/2・HTTP/3・WebSocket・gRPC・WebRTC | ネットワーク入門 NEW 2026-06-22 12:17:25
- gRPC とは HTTP/2 + Protocol Buffers の高速 RPC | ネットワーク入門 NEW 2026-06-22 12:17:25
- HTTP/3 (QUIC) とは UDP ベースの低遅延 Web 通信 | ネットワーク入門 NEW 2026-06-22 12:17:25
- WebRTC とは ブラウザ間 P2P の音声・映像・データ通信 | ネットワーク入門 NEW 2026-06-22 12:17:25
- 証明書と認証局(CA)とは|X.509・信頼チェーン・DV/OV/EV・失効(CRL/OCSP)を解説 NEW 2026-06-22 12:17:24
- ファイアウォールとは|パケットフィルタ・ステートフル・DMZ・次世代FW(L4/L7)を解説 NEW 2026-06-22 12:17:24
- iptables/nftablesとは|テーブル・チェーン・ルール例・永続化をLinux視点で解説 NEW 2026-06-22 12:17:24
- HAProxy とは frontend/backend と設定例 | ネットワーク入門 NEW 2026-06-22 12:17:24
- TLS/SSLの仕組み|ハンドシェイク・暗号スイート・前方秘匿性・証明書検証をわかりやすく解説 NEW 2026-06-22 12:17:24
- CDN とは エッジキャッシュ・TTL・Cloudflare/CloudFront | ネットワーク入門 NEW 2026-06-22 12:17:24
コメントを削除してもよろしいでしょうか?