xxxxxxxxxx
// 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 \Database\Factories\MyModelFactory::new();
}
//On your factory, add this
protected $model = \App\Models\MyModel::class;
xxxxxxxxxx
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
xxxxxxxxxx
php artisan tinkerProduct::factory()->count(500)->create()
xxxxxxxxxx
factory(App\User::class, 30)->create()->each(function($user) {
$entity = factory(App\Entity::class)->make();
$address = factory(App\Address::class)->create([
'entity_id' => $entity
]);
$user->entities()->save($entity);
});
xxxxxxxxxx
//Creates models without storing them in DB
$users = User::factory()->count(3)->make();
xxxxxxxxxx
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