What does your command class look like? Did you register the command?
Check the docs: http://laravel.com/docs/5.1/artisan#command-structure
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"]
];
}
Not sure, but I think that should be:
public function getArguments() {
return [
['site-url', null, InputArgument::REQUIRED, "learn.x.com or learn.y.com"]
];
}
What version are you using?
Guys, I am using Laravel 4.2.
Of course, it is registered.
--site-url is an option, not an argument, so why use getArguments()?
@toniperic what should I use then?
getOptions()? Read the docs, not sure, long time ago since I've used L4.2.
@toniperic Doesn't work either.
@EliasSoares , that didn't work either, says, option does not exist.
Here i use this as getOptions ()...
@EliasSoares Okay, and what is your command like?
@aligajani it does work, just read the docs.
"Option mode \"learn.x.com or learn.y.com\" is not valid.
@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,
),
);
}
@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="..."]
@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.
Line 46 (and probably some more lines)
$this->site = $this->argument('site-url');
And again - you're not working with arguments, but options!
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.
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
You aren't using arguments though, change it to getOptions()...
@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 ,and how do I run the command?
@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.
Right, and it gives me this:
[ErrorException]
array_merge() expects at least 1 parameter, 0 given
@aligajani Can you paste your command class as it is now please.
@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.
Correct.
@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.
@aligajani Please take the time to accept an answer if you’re original query has been answered.
Please or to participate in this conversation.