Search code examples
phplaravelconsolelaravel-artisan

PHP artisan run seeder from new folder in /database/seeds


I have created a new folder in (/database/seeds/) so for now I have a seeder in such directory (/database/seeds/DatabaseTester/Users.php) and I want to run it in my tests. How can I run my seeder using code in my tests?

php artisan db:seed --class= is not working for me, maybe I'm doing wrong, I'm confused.

UPD:

enter image description here


Solution

  • This is how its gonna work:

    add namespace Seeder\DatabaseTester; to your seeder

    add use Illuminate\Support\Facades\Artisan; at the top of your test

    use to run Artisan::call('db:seed', ['--class' => 'Seeder\DatabaseTester\Users']);

    This one will work for any folder, just don't forget to add Seeder\ before your path to seeder.