Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ell's avatar
Level 3

Database seeders within package

Hello, guys!

I'm working on a small reusable package and one part of it - to publish some seeds. I was wanted to automate this task, but was surprised that couple of old ways to solve it were removed in L5.

Is there is a way to do call seeds from package without manually copying them to the applications folder? I've tried latest 5.1.x version for the tests.

There is a topic how to deal with package seeds, but it's one year old and it seems to be outdated for current release.

I've tried to add namespace to my seeds and in package's composer.json file, but no luck, Laravel won't see and use them:

"autoload": {
    "psr-4": {
        "Vendor\\Package\\": "src/",
        "Vendor\\Package\\Database\\Seeds": "database/seeds/"
    }
},
composer dump-autoload
php artisan db:seed --class="Vendor\Package\Database\Seeds\PackageSeeder"

Output:

[ReflectionException] Class Vendor\Package\Database\Seeds\PackageSeeder does not exist

After that I've tried to call it right from the default DatabaseSeeder application class:

<?php

use Vendor\Package\Database\Seeds\PackageSeeder;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        $this->call(PackageSeeder::class);
    }
}

Same result :'(

0 likes
4 replies
davestewart's avatar

Did you mean to include the Vendor (and Package) namespace?

willvincent's avatar

Surely your namespace isn't "Vendor\Package" That's all kinds of wrong..

Ell's avatar
Level 3

I've wrote Vendor\Package as example. For real it's Cog\Currency. And I've defined namespace in Seeder class and added it in composer autoloading, right as I've added src files and unit tests.

I need to call package seeds from applications without copying them to application's database/seeds folder.

bjuppa's avatar

I ran into the same issue! ...and I had made the same mistake: forgetting to put double backslash at the end of the Seeds namespace in the psr-4 section of composer.json!

1 like

Please or to participate in this conversation.