InterNACHI/modular

Laravel 8 Factories namespaces

Closed this issue · 6 comments

I've noticed when a factory is created its namespace is using the default

Database\Factories

instead of the vendor/package namespace ie:

Dcblogdev\Contacts\Database\Factories

this is generated using the normal Laravel command with the --module flag. Is this expected or should I be generating the factories in a different way?

also, what's the recommended way to run seeders from packages?

I can do

php artisan db:seed --module=contacts

when doing db:seed the module seeders are not picked up, I can run the seeder if I add to the main DatabaseSeeder class directly. Is there a way to run specific module seeders?

I've noticed when a factory is created its namespace is using the default

What exact version of Laravel are you using?

also, what's the recommended way to run seeders from packages?

Hm. php artisan db:seed should just work. It may be that something changed with the seeder in a recent Laravel release and we'll need to tweak the Modular implementation. Once you let me know what version you're experiencing this with, I'll take a look.

thanks, I'm using Laravel 8.49.0

db:seed only works for me if I add the package seeder to the main DatabaseSeeder class

Alright. I should have fixes for the namespace issues. I'll publish them with the next release.

As for db:seed — I was wrong. Laravel's default behavior is to just run DatabaseSeeder unless you specify the seeder class you want to run. Maybe we can add a module-specific option in the future, but right now you pretty much treat seeders the same as any other.

Either:

  1. Add them to your root DatabaseSeeder class
  2. Call them with --class=Modules\MyModule\Database\Seeders\MySeeder

Actually, I take that back. I've added a db:seed implementation. Should be available in the next release!

Should be fixed in 1.4.0