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

JKirkInTexas's avatar

PHP Error: Class "Database\Factories\User" not found

I was in Laravel 8 from Scratch in lesson: Turbo Boost With Factories. At 6:33 and I was getting this error when I tried to run it via their directions: PHP Error: Class "Database\Factories\User" not found in /Users/JKirkInTexas/blog/database/factories/PostFactory.php on line 20 . Does anyone know what is the solution? I have tried changing a few things, but I am not sure what will fix this. Thank you for any help anyone can provide.

0 likes
5 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Import the model at the top

use App\Models\User;
JKirkInTexas's avatar

@Sinnbeck Indeed I was in the wrong file, I had to bring in the category as well but once that was done it works. My code editor does not automatically use the files it needs. It seems like that will have to be something I check. Thank you again sir.

Sinnbeck's avatar

@JKirkInTexas happy to help. If you make a new thread explaining the issue, I am sure someone can help. I use phpstorm where it happens almost automatically, but others programs might need some set up

Please or to participate in this conversation.