factory error while installing in laravel 9
malozaibi opened this issue · comments
Mohammed Alozaibi commented
Describe the bug
I get Target class [Illuminate\Database\Eloquent\Factory] does not exist.
error while installing in Laravel 9.
Laravel Version
Laravel 9
George Manyara commented
Use this solution
!!!the loadFactoriesFrom method should not be used, it's deprecated and it will be removed from Laravel in a future version!!!
What you should do, is overwrite the newFactory() method, that the HasFactory trait provides, and just register the factory there. I would be happier for a more "global" solution but this seems to be a good solution and doing it the way laravel intended it to. Hacking stuff will bite you in the future :)
/**
- Create a new factory instance for the model.
- @return Factory
*/
protected static function newFactory(): Factory
{
return FactoryClass::new();
}