php artisan make:factory CommentFactory
return [
'name' => $this->faker->name,
'text' => $this->faker->text()
];
public function run()
{
Comment::factory()
->times(3)
->create();
}
php artisan db:seed
php artisan tinkerProduct::factory()->count(500)->create()
factory(AppUser::class, 30)->create()->each(function($user) {
$entity = factory(AppEntity::class)->make();
$address = factory(AppAddress::class)->create([
'entity_id' => $entity
]);
$user->entities()->save($entity);
});
php artisan make:factory UserFactory
// If you factory is out of standard, you can set an specifc
// On your model, create a static method named newFactory
protected static function newFactory()
{
return DatabaseFactoriesMyModelFactory::new();
}
//On your factory, add this
protected $model = AppModelsMyModel::class;
$users = User::factory()->count(3)->make();
php artisan make:model ModelName -a
// -a stands for all (Model, Controller, Factory and Migration)
// Note: The above command will work successfully in Laravel 5.5 or > versions
//Creates models without storing them in DB
$users = User::factory()->count(3)->make();