LoginSignup
0
0

More than 1 year has passed since last update.

【Laravel備忘録】「Target class [○○Controller] does not exist.」②

Posted at

【Laravel備忘録】

以前、「Target class [○○Controller] does not exist.」についての記事を書きましたが、もう1つエラー回避方法があったので今回はそちらを紹介します。

useでコントローラをインポートする

前回はファンクション内の参照の仕方でエラーを回避しました。
今回も参照の仕方を変えるので回避方法としては似たようなやり方ですが、違う書き方なのでご紹介します。
まずはrouteのファイルでuse宣言してコントローラをインポートします。

use App\Http\Controllers\HelloController;

そしたら次にRouteの中でコントローラを参照する方法ですが下記のように参照します。

Route::get('hello', [HelloController::class, 'index']);

この記載方法でもエラー回避できましたのでもし困っている方がいましたらこの方法も試してみてください。

では本日はこの辺で。
ありがとうございました。
いい週末をお過ごしください。

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