php - Why custom constructor in Laravel command cause "Invalid argument supplied for foreach"? -


i have created command follow:

<?php use illuminate\console\command; use symfony\component\console\input\inputoption; use symfony\component\console\input\inputargument; class schedulescommand extends command {      protected $name = "mod:check";      protected $description = "checks database upcoming schedules.";      protected $mod;      public function __construct (model $mod){         $this->mod = $mod;     }      public function fire(){         $this->line('checking database');         $this->mod->f1 = 1;         $this->mod->f2 = "test";         $this->mod->f3 = 'command';         $this->mod->save();     } ?> 

i following error - don't know why --

{"error":{"type":"errorexception","message":"invalid argument supplied foreach()","file":"\/home\/test\/documents\/account1\/php scripts\/project\/vendor\/symfony\/console\/symfony\/component\/console\/application.php","line":409}} 

can tell me might going wrong?

this artisan.php file:

 $mod = new model;  $artisan->add(new schedulescommand($mod)); 

you should calls parent constructor when creating laravel command.

in constructor add parent::__construct() first line follow:

public function __construct (model $mod) {     parent::__construct();     $this->mod = $mod; } 

keep in mind calling parent constructor allow laravel configure name, description, , parameters on console command make things little easier us.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

visual studio - TFS will not accept changes I've made to a Java project -