Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a custom Artisan command in a Controller | Laravel

I'm trying to excute a custom Artisan command in a Controller, but it throws an CommandNotFound Exception. In the implementation I run the command, instead of excuting the whole command 'php artisan scan {url}', I just run scan {url} because of this Answer: Running Artisan Command. I don't understand what I did wrong?

Custom Artisan Command signature

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}';

Implementation

switch ($select) {

   case 'full':

     \Artisan::call('scan ' . $customer->cms_url); //url == http://localhost:8888
     return $request;

     break;
}

Error

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)
like image 748
melkawakibi Avatar asked Jan 03 '23 12:01

melkawakibi


1 Answers

First register your Artisan command in app/console/Kernel.php: in commands array add your command Class. After that you can call your command like this

\Artisan::call('scan', ['url' => "{$customer->cms_url}"]);

You must wrap the url in " " otherwise it will not set the full string

like image 195
Petyo Tsonev Avatar answered Jan 08 '23 07:01

Petyo Tsonev