在控制器中调用自定义 Artisan 命令 | Laravel
Calling a custom Artisan command in a Controller | Laravel
我试图在控制器中执行自定义 Artisan 命令,但它引发了 CommandNotFound
异常。在实现中,我 运行 命令,而不是执行整个命令 'php artisan scan {url}',我只是 运行 扫描 {url} 因为这个答案:。我不明白我做错了什么?
自定义Artisan命令签名
protected $signature = 'scan {url}
{--r= : y or n | to follow or not to follow the robot.txt}
{--fm= : set follow mode}
{--u= : username}
{--p= : password}
{--s : SQL module}
{--x : XSS module}';
实施
switch ($select) {
case 'full':
\Artisan::call('scan ' . $customer->cms_url); //url == http://localhost:8888
return $request;
break;
}
错误
1/1) CommandNotFoundException
There are no commands defined in the "scan http" namespace.
in Application.php (line 548)
at Application->findNamespace('scan http')
in Application.php (line 582)
at Application->find('scan http://localhost:8888')
in Application.php (line 205)
首先在 app/console/Kernel.php
中注册您的 Artisan 命令:在命令数组中添加您的命令 Class。之后你可以像这样调用你的命令
\Artisan::call('scan', ['url' => "{$customer->cms_url}"]);
您必须将 url 包裹在 " "
中,否则它不会设置完整的字符串
我试图在控制器中执行自定义 Artisan 命令,但它引发了 CommandNotFound
异常。在实现中,我 运行 命令,而不是执行整个命令 'php artisan scan {url}',我只是 运行 扫描 {url} 因为这个答案:
自定义Artisan命令签名
protected $signature = 'scan {url}
{--r= : y or n | to follow or not to follow the robot.txt}
{--fm= : set follow mode}
{--u= : username}
{--p= : password}
{--s : SQL module}
{--x : XSS module}';
实施
switch ($select) {
case 'full':
\Artisan::call('scan ' . $customer->cms_url); //url == http://localhost:8888
return $request;
break;
}
错误
1/1) CommandNotFoundException
There are no commands defined in the "scan http" namespace.
in Application.php (line 548)
at Application->findNamespace('scan http')
in Application.php (line 582)
at Application->find('scan http://localhost:8888')
in Application.php (line 205)
首先在 app/console/Kernel.php
中注册您的 Artisan 命令:在命令数组中添加您的命令 Class。之后你可以像这样调用你的命令
\Artisan::call('scan', ['url' => "{$customer->cms_url}"]);
您必须将 url 包裹在 " "
中,否则它不会设置完整的字符串