1

I have seeder classes that I confirmed they could run individually, and I'm trying to run them from another seeder class in the same namespace.
I'm getting an error saying that the class run from another seeder is not found.
I'm using OctboerCMS build 419.

Seeder Class calling subseeder

<?php namespace Cocci\Custom\Updates;
use Seeder;

class SeedTablesCocciPedale extends Seeder
{
    public function run()
    {
        $this->call('Cocci\Custom\Updates\SeedTablesCocciBike005');
        $this->call('Cocci\Custom\Updates\SeedTablesCocciColor');
//        $this->call(SeedTablesCocciBike005::class);
//        $this->call(SeedTablesCocciColors::class);
    }
}

Seeder called by another seeder

<?php namespace Cocci\Custom\Updates;

use Seeder;
use Cocci\Custom\Models\Product;
use Cocci\Custom\Models\Part;
use Cocci\Custom\Models\PreviewType;
use Cocci\Custom\Models\PartType;
use Cocci\Custom\Models\PartPreviewPosition;

class SeedTablesCocciBike005 extends Seeder
{
    public function run()
    {
        $partTypeSetAll = PartType::create([
            'name' => 'set_all',
            'category' => PartType::CAT_ALL_PARTS,
        ]);
        $partTypeNoPaintParts = PartType::create([
            'name' => 'no_paint_parts',
            'category' => PartType::CAT_NON_CUSTOMIZABLE,
        ]);
        ...
    }
}

Error

% php artisan plugin:refresh Cocci.Custom
Rolled back: Cocci.Custom
Reinstalling plugin...
PHP Fatal error:  Class 'Cocci\Custom\Updates\SeedTablesCocciBike005' not found in /Library/WebServer/Documents/cocci-custom/vendor/laravel/framework/src/Illuminate/Database/Seeder.php on line 62

[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Cocci\Custom\Updates\SeedTablesCocciBike005' not found 

I tried both ways specifying the class by string of fully qualified name and with class keyword, but neither worked. Probably these seeder classes are not loaded?
What should I do?
Thanks in advance.

kanji
  • 729
  • 9
  • 14
  • Did you run 'composer dump-autoload' and tried again? Furthermore if your Bike005 and Color seeder are in the same directory you dont need the full, namespaced, path - just the class would be enough. – codedge May 28 '17 at 09:02
  • @codedge thanks. But unfortunately it didn't work... – kanji May 28 '17 at 09:47
  • Can you post your Bike005 class? – codedge May 28 '17 at 10:02
  • I put Bike005 seeder class, but removed irrelevant parts because it had more than a thousand lines. – kanji May 28 '17 at 13:13

1 Answers1

0

When using a seeder class to call additional seeder classes, you need to make sure you're autoloading the seeder classes.

Assuming you're seeder classes are called seed_tables_cocci_bike_005.php and seed_tables_cocci_color.php, you can add these files to you're classmap dev autoloader as follows.

"autoload-dev": {
    "classmap": [
        "tests/TestCase.php",
        "tests/UiTestCase.php",
        "tests/PluginTestCase.php",
        "plugins/cocci/custom/updates/seed_tables_cocci_bike_005.php",
        "plugins/cocci/custom/updates/seed_tables_cocci_color.php"
    ]
}

Remember to composer dumpautoload once your composer.json file has been updated.