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?

More than 1 year has passed since last update.

LaravelでTarget class [App\Http\Controllers\〇〇Controller] does not exist.が出た時の対処法

Posted at

この記事の背景

Laravelサーバーを起動する時に以下のエラーが出てしまい止まってしまいました。

スクリーンショット 2023-02-26 3.56.03.png

調べたらなんだそんなものかーって感じでしたね。

解決法

下の参考資料をヒントにしたら解決できました。

UsersController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index()
    {
        return view('welcome');
    }
}

usersControllerを作成しました。

web.php
<?php

Route::get('/', 'UsersController@index');

ルーティングでは***'UsersController@index'で設定していたにもかかわらず
usersControllerでは
UserController***になっていました。UsersControllerに修正しました。

UsersController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UsersController extends Controller
{
    public function index()
    {
        return view('welcome');
    }
}

よくあるミス

参考資料にも書いてあるのですが、Target class ~ does not exist.だと
以下の原因があるみたいです。

1. コントローラのnamespaceが間違っている

2. 複製したコントローラのエクステンドが違う

3. ルーティングのスペルミスかパスが違う

4. コントローラーに記述した use App\Xxxx\xxxxで大文字小文字の違い

下の資料に詳しく書いてあるので参考にしてみてください。

参考資料

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?