我正在为我的 Laravel 实例的数据库编写一些播种器。我正在使用 Laravel Scout TNTSearch driver .
php artisan tntsearch:import App\\MyModel
我想从我的播种机调用这个命令。我查看了实现,它非常复杂,我不想重构、等待合并的拉取请求或将实现复制并粘贴到我的文件中。
我试过的播种机内部:
$this->call('tntsearch:import', ['model' => App\User::class]);
但是 $this
指的是播种机,call
方法需要另一个播种机,而不是控制台命令。
我想从我的播种机内部调用 artisan 命令。 这可能吗?
更新
我最终在播种机中做了这个:
exec('php artisan tntsearch:import App\\User');
这有效但感觉很脏。是否有另一种不使用 exec()
的简单方法?
最佳答案
你可以使用Artisan
门面:
\Artisan::call('tntsearch:import', ['model' => App\User::class]);
关于php - Laravel 如何从数据库播种机调用控制台命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42791500/