Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aligajani's avatar

Why is my Artisan command not running?

I have this and whenever I try to run it like:

php artisan commandName --site-url=learn.x.com it says:

                                           
  [RuntimeException]                       
  The "--site-url" option does not exist.  
                                           
  public function getArguments() {
        return [
            ['site-url',
             InputArgument::REQUIRED,
             "learn.x.com or learn.y.com"]
        ];
    }
0 likes
30 replies
EliasSoares's avatar

Not sure, but I think that should be:

 public function getArguments() {
        return [
            ['site-url', null, InputArgument::REQUIRED, "learn.x.com or learn.y.com"]
        ];
    }       
aligajani's avatar

Guys, I am using Laravel 4.2.

Of course, it is registered.

toniperic's avatar

--site-url is an option, not an argument, so why use getArguments()?

toniperic's avatar

getOptions()? Read the docs, not sure, long time ago since I've used L4.2.

martinbean's avatar

@aligajani If you read the Laravel 4.2 documentation on Artisan development, you will find the following:

When defining options, the array definition values represent the following:

array($name, $shortcut, $mode, $description, $defaultValue)

Therefore, your getOptions() should probably look something like this:

public function getOptions()
{
    return array(
        array(
            $name = 'site-url',
            $shortcut = null,
            $mode = InputOption::VALUE_REQUIRED,
            $description = 'One of learn.x.com or learn.y.com',
            $defaultValue = null,
        ),
    );
}
aligajani's avatar

@martinbean Thank you for your reply, but I get this below

aligajani@Alis-iMac:~/Code/base-api$ ./artisan backport-purchases --site-url="learn.x.com"
                                          
  [InvalidArgumentException]               
  The "site-url" argument does not exist.  
   
backport-purchases [--site-url="..."]
martinbean's avatar

@aligajani Can you post the code of your backport-purchases command class, please. You’re obviously still referencing an argument instead of an option somewhere, but we can’t see from what you’ve provided us with so far.

toniperic's avatar

Line 46 (and probably some more lines)

$this->site = $this->argument('site-url');

And again - you're not working with arguments, but options!

martinbean's avatar

As @toniperic says, you’re still referencing $this->argument() in your command. site-url isn’t an argument, it’s an option. Use $this->option('site_url') instead. Then have a read up on the differences between arguments and options.

aligajani's avatar

Okay, you guys have confused me. I was initially using getArguments and based upon that, line 46 is fine.

Yet it doesn't work.

public function getArguments() {
        return [
            ['site-url',
             InputArgument::REQUIRED,
             "learn.academyft.com or learn.shawacademy.com"]
        ];
    }

Gives me this below when I ran backport-purchases --site-url="learn.academyft.com"

  [RuntimeException]                       
  The "--site-url" option does not exist. 

Okay, then I ran this ./artisan backport-purchases learn.academyft.com

I got this:

  [ErrorException]                                     
  array_merge() expects at least 1 parameter, 0 given 
joedawson's avatar

You aren't using arguments though, change it to getOptions()...

martinbean's avatar

@aligajani You’re not reading. You should be defining your --site-url option with the getOptions() method and the sample code I gave you (not getArguments()) and accessing it with $this->option('site-url') and not $this->argument().

Again, I suggest you read up on the difference between arguments and options in console commands: http://laravel.com/docs/4.2/commands#building-a-command

martinbean's avatar

@aligajani The same way: artisan backport-purchases --site-url="learn.x.com"

We’re been telling you how to fix your command class’s code to work with the command you were issuing.

aligajani's avatar

Right, and it gives me this:

  [ErrorException]                                     
  array_merge() expects at least 1 parameter, 0 given 
martinbean's avatar

@aligajani I can’t see the array_merge() function used any where in your command class, so you must have a bug somewhere else.

Try running artisan backport-purchases --site-url="learn.x.com" --verbose. The verbose option might give you a file and the line number the error occurs.

martinbean's avatar

@aligajani Right? So that has nothing to do with your original issue. If your original issue has been fixed then you can accept an answer and move on to fixing the new issue.

martinbean's avatar

@aligajani Please take the time to accept an answer if you’re original query has been answered.

1 like

Please or to participate in this conversation.