Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JunaNougsan's avatar

how to run multiple database seeds?

I have the following structure:

Class Cuopon in the database/migration i have 4 Migration defined === 4 tables.

Users, Cuopons, Restaurants, Scans In the database/Seeds i have the DatabaseSeeder + the 4 seeder for each table.

The DatabaseSeeder contains the following:

$this->call('CuoponTableSeeder');.

and the CuponTableSeeder.php contains the following:

$cuopons = factory(Cuopon::class, 10)->create();

And the ModelFactory contains the following:

$factory->define(App\Cuopon::class, function (Faker\Generator $faker) { return [ 'restaurant_id' => rand(0, 300), 'product_id' => rand(0, 300), 'expires' => $faker->dateTimeBetween('now', '+1 years') ]; }); After running php artisan migrate and then php artisan db:seed will create all the tables, and fills up with 10 rows of dummy data the cuopons table. The question is how can i add more factories in the ModelFactory to be able to fill up the rest of the tables also? I am through the documentation but this does not seems to make sense for me at first.

Thank you in advance!

0 likes
1 reply
MohamedTammam's avatar

Firstly, Please format your code by surrounding it with ```

You can use each to pass the created model properties to other factories.

$cuopons = factory(Cuopon::class, 10)->create()->each(function($coupon) {
	// That will run for each created Cuopon.
});

Please or to participate in this conversation.