2017-09-03 118 views
0

我試圖在控制器中執行自定義Artisan命令,但它會拋出CommandNotFound異常。在執行過程中,我運行命令,而不是執行整個命令'php artisan scan {url}',我只是運行scan {url},因爲這個答案:Running Artisan Command。我不明白我做錯了什麼?在Controller中調用自定義Artisan命令Laravel

定製工匠命令簽名

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) 

回答

1

首先在app/console/Kernel.php的命令中註冊您的Artisan命令Array添加您的命令Class。在此之後,你可以打電話給你的命令,這樣

\Artisan::call('scan',[ 'url' => "{$customer->cms_url}" ]); // You must wrap the url in " " otherwise it will not set the full string

+0

謝謝您的答覆。這是正確的解決方案。 – melkawakibi