mercredi 29 avril 2020

When and how do you use Laravel Factory and Seeding

I'm confused about using them, so want to make sure I'm using them correctly and get to know if there is any other use case". Here are my use cases:

1- In unit tests

public function test_index_returns_view()
{
    ...
    $streets = factory(Street::class, 10)->make();
    ...
}

2- when I'm developing a new app, run the seeders like this to puplate DB

php artisan migrate:fresh --seed

3- for inserting some records in production, put something like this in a migration

Artisan::call('db:seed', array('--class' => 'YourSeederClass'));

Aucun commentaire:

Enregistrer un commentaire