Adjust Seeders integration for Package Development in Laravel 8

Viewed 159

I developed a package for an api in laravel.7.x. That api is delivered as an package for laravel. Now I want to upgrade it to laravel 8. Unfortunately I cannot get the seeders to work.

all package Seeders should executed after the

php artisan migrate:fresh --seed

command.

Appearantly the Seeder classes are not found. for Example 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. 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.

1 Answers

alright, the issue is solved.

Use the new way of including factories in laravel 8 i.e Models have this new function:

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.

Related