1

我有播种器类,我确认它们可以单独运行,并且我正在尝试从同一命名空间中的另一个播种器类运行它们。
我收到一条错误消息,提示找不到从另一个播种机运行的课程。
我正在使用 OctboerCMS build 419。

Seeder 类调用 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);
    }
}

由另一个播种机调用的播种机

<?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,
        ]);
        ...
    }
}

错误

% 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 

我尝试了两种通过完全限定名称字符串和class关键字指定类的方法,但都没有奏效。可能这些播种机类没有加载?
我应该怎么办?
提前致谢。

4

1 回答 1

0

当使用播种器类调用其他播种器类时,您需要确保自动加载播种器类。

假设你调用了播种器类seed_tables_cocci_bike_005.phpseed_tables_cocci_color.php你可以将这些文件添加到你的类映射开发自动加载器中,如下所示。

"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"
    ]
}

请记住,composer dumpautoload一旦您的 composer.json 文件已更新。

于 2019-11-28T15:37:26.647 回答