Small problem when trying to create a custom artisan command – Laravel

I came across a small issue that had me stumped for a while, I was creating a custom artisan command for Laravel and it returned this error when trying:

PHP artisan dump-autoload
{"error":{"type":"ErrorException","message":"Invalid argument supplied for foreach()","file":"\/var\/www\/elections\/vendor\/laravel\/framework\/src\/Illuminate\/Console\/Command.php","line":77}}

Try as I might I couldn’t figure it out, I removed my code bit by bit and it still came up with the error.

Then I realised that I didn’t need any options so I commented out the returning array: e.g.

	protected function getOptions()
		//return array(
		//	array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),

I changed it to:

	protected function getOptions()
		return array(

Then tried the dump-autoload again and no problems, so the solution is here in case anyone has the same issue.

3 thoughts on “Small problem when trying to create a custom artisan command – Laravel”

  1. Thanks for this, Adam! I’m having trouble still – to clarify, are you commenting out this line in the console.stub file? I comment that out and still receiving that error. Thanks!

    1. Hi Adam! I just figured out my issue and it seemed to be totally separate for this – had a typo within the actual for loop (silly mistake!). Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *