[ACCEPTED]-Call database seeder from a subfolder-laravel-4

Accepted answer
Score: 28

You shouldn't need to edit your classmap on your 4 project, just make sure to run

composer dump-autoload

after moving 3 your class to a subfolder.

Once you've done 2 that, run this (no need to mention testData 1 here)

php artisan db:seed --class="myTestSeeder"
Score: 4

You need to tell the autoloader how to load 4 your new class. This is relatively simple; add 3 the following to your composer.json in the 2 classmap property:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/database/seeds/testData"  // <-- Add this
    ]
},

After that, run composer dump-autoload and your seed 1 file should now be loaded successfully.

Score: 1

When you create new Seeder class, for example:

php artisan make:seeder Authorization/CreateAppRoleSeeder

As 5 a result, get new class:

    <?php

    use Illuminate\Database\Seeder;

    class Authorization/CreateAppRoleSeeder extends Seeder
    {
        /**
         * Run the database seeds.
         *
         * @return void
         */
        public function run()
        {
            //
        }
    }

You have to replace 4 class Authorization/CreateAppRoleSeeder extends Seeder with class CreateAppRoleSeeder extends Seeder.

Next, execute the dump composer command:

composer dump

After 3 add class to file 'database\Seeder\DatabaseSeeder' In 2 my case, for example:

    <?php

    use Illuminate\Database\Seeder;

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

After that execute 1 the command

php artisan db:seed

In my case

php artisan db:seed --class=CreateAppRoleSeeder

So will work ;)

More Related questions