简体   繁体   English

为 Laravel 8 中的包开发调整 Seeders 集成

[英]Adjust Seeders integration for Package Development in Laravel 8

I developed a package for an api in laravel.7.x.我在 laravel.7.x 中为 api 开发了一个包。 That api is delivered as an package for laravel.该 api 是作为 laravel 的一个包提供的。 Now I want to upgrade it to laravel 8. Unfortunately I cannot get the seeders to work.现在我想将它升级到 Laravel 8。不幸的是我无法让播种机工作。

all package Seeders should executed after the所有包 Seeder 都应该在

php artisan migrate:fresh --seed

command.命令。

Appearantly the Seeder classes are not found.显然没有找到 Seeder 类。 for Example Target class [PostSeeder] does not exist.例如Target class [PostSeeder] does not exist.

But it does exist, it's even in the same namespace.但它确实存在,甚至在同一个命名空间中。

Now I'm trying to start in with a DatabaseSeeder and this one IS found.现在我正在尝试从 DatabaseSeeder 开始,并且找到了这个。 But from there the other Seeders can't be triggered.但是从那里无法触发其他播种机。

Does anyone has an Idea what can be tried or has a hint or code snippet for this problem?有没有人知道可以尝试什么或有针对此问题的提示或代码片段?

Many thanks in advance.提前谢谢了。

alright, the issue is solved.好了,问题解决了。

Use the new way of including factories in laravel 8 ie Models have this new function:使用在 laravel 8 中包含工厂的新方式,即模型具有以下新功能:

use Acme\YourPackage\Database\Factories\PostFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;

protected static function newFactory()
{
    return PostFactory::new();
}

and make sure to call it like:并确保将其称为:

enter $this->call('Acme\YourPackage\Database\Seeders\PostSeeder');

after that make your sure your namespace and class paths are set correctly.之后确保您的命名空间和类路径设置正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM