4

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)
melkawakibi
  • 823
  • 2
  • 11
  • 26

2 Answers2

10

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

fdehanne
  • 1,658
  • 1
  • 16
  • 32
Petyo Tsonev
  • 567
  • 2
  • 6
  • 19
0
\Artisan::call('database:backup');//database:backup is a command
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Jun 25 '22 at 13:03