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
you can use like this:
\App\Models\User::factory()->count(2)->create();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With