Sunday, August 9, 2015

Easy way to set multiple seeders in Laravel 5.1

Multiple seeders in a table:

For entry multiple data in table it is a easy way to create a seeder.

For creating a seeder run the following command:

php artisan makd:seeder ClassNameSeeder

After this , in its run() function, write it

        $zones = [
            ['zone_id' => 1, 'zip' => '94133', 'rate' => '1.00'],
            ['zone_id' => 1, 'zip' => '94111', 'rate' => '2.00'],
            ['zone_id' => 1, 'zip' => '94104', 'rate' => '3.00'],
            ['zone_id' => 2, 'zip' => '94109', 'rate' => '4.00']

        ];

            \App\Zone::insert($zones);


Here the upper array is the multiple value , which you wana enter in your table.

After that run this command.

php artisan db:seed --class=ClassNameSeeder
Thanks

No comments:

Post a Comment