Reputation: 65
I need to run factory using tinker but my model isn't in app folder like this->App\Models\User::factory()->count(2)->create();
the path is-> Modules\Menu\Entities\MenuPosition and when I run tis command
php artisan tinker
Modules\Menu\Entities\MenuPosition::factory()->count(2)->create();
there is error
Class 'Database/Factories/Modules/Menu/Entities/MenuPositionFactory' not found in C:/laragon/www/menu--test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php on line 656
Upvotes: 4
Views: 13884
Reputation: 51
you can use like this:
\App\Models\User::factory()->count(2)->create();
just write the namespace of the model you want to use
Upvotes: 5
Reputation: 50491
You can override the newFactory
method on this model:
/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return \Modules\Menu\Database\Factories\MenuFactory::new();
}
Or you can look into the documentation to see how to adjust how the factory is looked up based on the model.
Upvotes: 1