Laravel 5 transfers data from the controller to the command

I am trying to pass an array from my controller to my command. See code below

Queue::push(new SendReminderPush(),array('data' => $data));

But when I call a command, I always get an exception.

Argument 1 missing for App \ Commands \ SendReminderPush :: handle ()

This is my descriptor function in the command class:

public function handle($data){
   foreach($data as $d){
    do something
   }
}

Please help me. What am I doing wrong?

+4
source share
1 answer

In Laravel 5, it really depends on what $data. If it is an array and you want the Laravel map to automatically display, you would do something like this:

$this->dispatchFromArray('App\Commands\SendReminderPush', $data);

Say yours $datalooks like this:

$data = array('name' => 'Test', 'email' => 'test@example.com');

In yours SendReminderPushyou should map this in the constructor:

public function __construct($name, $email) {
   $this->name = $name;
   $this->email = $email;
}

( ) :

public function handle(){
   $this->doSomething($this->name);
}

, Command Bus Laravel 5.

+4

All Articles