Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Class not found, but can't use Composer right now, what can I do?

I added a Model class file MyModel.php manually (created the file inside the Models folder, not via artisan).

But now I get error: Class App\Model\MyModel not found when using it from another Model:

public function MyModel() {
     return this->hasOne('App\Model\MyModel');
}

and I can't use composer dump-autoload right now which I think could have solved this issue. Is there another way to do it manually?

Thanks!

0 likes
4 replies
Sinnbeck's avatar

If you copy its content to notepad and delete the file, can you run it?

1 like
Ligonsker's avatar

@Sinnbeck You mean delete the MyModel.php file? If so I just did it. I forgot to mention (but edited the main post), that I am using it from another model, where the error is triggered

automica's avatar
automica
Best Answer
Level 54

You shouldn't need to run composer dump-autoload when adding classes.

More likely your namespace isn't correct within the Model. Make sure its the same as others in the Models folder.

namespace should match plural App\Models to match your Models directory

1 like
Ligonsker's avatar

@automica @sinnbeck sorry, I guess I'm too tired. I copied the class code form another model and forgot to change the class name :)

Please or to participate in this conversation.