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

austenc's avatar

Seeders within a package?

Is this possible? After installing my package via composer, artisan doesn't pick up the seeders. I can't seem to find much on the web about seeds within packages, does anyone have experience with this?

I'm the sole developer of the package, trying to use it as a base layer of components to form other apps. From what I understand, the best option is to copy the seeds to my app and update / version them manually within it..

Edit: Pretty sure I figured it out -- namespace the seeders and then call the namespaced (package) seeder from my app's seeder... seems simple enough!

0 likes
8 replies
aedart's avatar

Could you give an example of you solution?

I have a very similar, in which I am trying to seed a table, located inside my workbench-package

Gufran's avatar

Edit: Pretty sure I figured it out -- namespace the seeders and then call the namespaced (package) seeder from my app's seeder... seems simple enough!

and if it is not your app then you can create an artisan command and call the Seeder::run() method on command execution.

For me it would be package:install where package is my package name. So:

php artisan package:install

would run migrations, seeder and publish the assets.

// ¢2

2 likes
NoorDeen's avatar

this is part of the help commmand with artisan db:seed

Options:
 --class               The class name of the root seeder (default: "DatabaseSeeder")

as you can see you can select the databaseSeeder class . this means you add new databaseSeeder class in your package and autoload it with composer then call :

php artisan db:seed YourDatabaseDeederClassName
1 like
austenc's avatar

I usually just run it by calling php artisan migrate --package="vendor/pkg".

aedart's avatar

What you mates are writing is all good - but, unless I am misunderstanding this, its a prerequisite that you install/publish the given package. Sadly, I am yet not at such a stage during development, and I am required to ensure that the given package(s) can be tested in the box.

So far, I "cheated" a bit in my tests - I simply specified the path, in the package's composer-file, where my seeders could be found, and invoke them directly from my migrations file(s).

Its important to note, that I do have lots of predefined data, and therefore I need seed. The downside is, bow my migrations are very tied to the seeders, which has changed my way of testing certain components.

I wish that L5 could modify its db:seed command a bit, and allow to specify the workbench-package, from where it should run its seeding. Then it would be working similar to the migrate-command.

austenc's avatar

@aedart -- I keep my seeders namespaced in the package, and you can call them from the workbench... you just need to do it with the migrate command...

php artisan migrate --seed --bench="package/vendor"

There's no way to call the seeds directly though (doesn't make much sense, I know)... but then again I haven't really needed to outside running a set of migrations... I'd think you could call them by the fully namespaced path if you needed to just call the seeder(s).

1 like
rootuser's avatar

This question is already old and was answered for Laravel 5.x, if I understood correctly. I now need the possibility to integrate seeds into my package in Laravel 10. Or, more precisely: I am looking for a way to insert default data into the database of my package; data that is required for the correct execution of my package. Can someone help me find a modern solution to this problem?

crslp's avatar

I'm usually against this approach, but in your case it might be an option to put a migration in the package that will call a seeder.

Please or to participate in this conversation.