Laravel 4 db seed specific seeder file

DatabaseLaravel 4

Database Problem Overview


I have an existing user table with information seeded via db:seed from UserSeeder.php. Now, I am adding new product table and want to seed information into product table. How can I prevent Laravel from seeding the UserSeeder into the database, but only the new ProductSeeder being seeded?

Thanks.

Database Solutions


Solution 1 - Database

You can call individual seed classes by their class name. From the docs.

> By default, the db:seed command runs the DatabaseSeeder class, which > may be used to call other seed classes. However, you may use the > --class option to specify a specific seeder class to run individually:

php artisan db:seed --class=ProductTableSeeder

In the example above, the ProductTableSeeder class should exist in database/seeds.

Solution 2 - Database

Here's a working example with the class full namespace:

Should use double backslashes \\.

Class name is DefaultBannersSeeder.

php artisan db:seed --class=App\\Containers\\Banners\\Data\\Seeders\\DefaultBannersSeeder

Solution 3 - Database

You can also edit your database/seeders/DatabaseSeeder.php file's $this->call() instruction:

<?php
namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call([
            UserTableSeeder::class,
            PermissionsSeeder::class
        ]);
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1995781View Question on Stackoverflow
Solution 1 - DatabaseSajan ParikhView Answer on Stackoverflow
Solution 2 - DatabaseMahmoud ZaltView Answer on Stackoverflow
Solution 3 - DatabaseAkshay K NairView Answer on Stackoverflow