1 month ago

Factory for model with custom namespace in Laravel 8

Posted 1 month ago by EvilAlex

Hi all!

I have a little problem with new factories.

My models has custom namespaces like App\Domain\Product\Models\Product. And i want use a simple factory namespaces like \Database\Factories\ProductFactory.

When i try to make them from seed class:


I get an error:

Class 'Database\Factories\Domain\Product\Models\ProductFactory' not found

But i dont want make so many folders, i want use Database\Factories\ProductFactory class.

When i make factory object manually, it works:


So, is there any way to use Model::factory() method and get \Database\Factories\ModelFactory object? Only delete new trait and make my own factory method?


Please sign in or create an account to participate in this conversation.