0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravelのルートエラー:該当箇所じゃないルート名の記述を正しくしたら何故か治った件を調査

Posted at
BadMethodCallException: Method App\Http\Controllers\SimpleController::index does not exist.

今日はこれが出ましたよ。
ルート設定は

Route::resource('simple', SimpleController::class);

の形。
今回の仕様は他のindexにお邪魔させてもらう形だったので、SimpleControllerにはindexは書いていなかったんだ。

なのに出たエラー

結局はdestroyメソッド内のリダイレクトの文字を間違えていたので、そこを修正したら治ったのだ。
ただ、そのリダイレクト先も他の〇〇.indexだったので別名だ。

私が考えたのは

コントローラー全体のメソッドをインスタンス化するときにタイプミスを発見。
削除メソッドのリダイレクトは通常Laravelではそのコントローラーのindexが入る。
indexを探したがindexがないよ。
エラー出す。

storeメソッドを呼び出すときもコントローラー全体を呼び出してルートの確認をするならまだ分かる。
がそういった機能はLaravelにはないようだ。

調査結果のまとめは下記

未実装メソッドは “呼ばれなければ無害”

Route::resource() で index ルートが登録されても、
実際に GET /resource を叩かなければ Laravel は index() を探しに行かない。
メソッドが無いことによる BadMethodCallException
リクエスト or リダイレクトが発生した瞬間 だけ起こる。

治した場所が直接関係していなかったのかな。
色々思い当たる節を治して回ったから覚えてない。。。もう一回同じ事象に遭遇しないかな。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?