I am writing some seeders for my Laravel instance's database. I'm using the Laravel Scout TNTSearch driver.
php artisan tntsearch:import App\\MyModel
I want to call this command from my seeder. I've looked at the implementation, and it is complicated enough that I don't want to refactor, wait for a merged pull request, or copy-and-paste the implementation into my files.
Inside the seeder I tried:
$this->call('tntsearch:import', ['model' => App\User::class]);
But $this
refers to the seeder, and the call
method is expecting another seeder, not a console command.
I want to call the artisan command from inside my seeder. Is this possible?
UPDATE
I ended up doing this inside the seeder:
exec('php artisan tntsearch:import App\\User');
This works but feels dirty. Is there another easy way without using exec()
?
You can use Artisan
facade:
\Artisan::call('tntsearch:import', ['model' => App\User::class]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With