laravel - Pass array to the command bus -
i'm trying understand how use laravel 5.0 command bus, struggling right, i'm looking few questions:
i'd dispatch array of memberids run through loop inside handle function of command.
$members:
array:2 [ 0 => "147" 1 => "148" ]
this array sent this:
$this->dispatch(new sendmail($members));
how access array in handle method of sendmail command? haven't found many examples, of them pass $command handler.
public function handle($command) { //this doesn't work foreach($command->members $memberid){ $contractor = contractor::find($memberid); }
do need return handler in order continue running other logic inside of original function?
since trying inject $members
array job's constructor method, need handle there.
then you'll able use array in hanle method.
// in job class protected $members; public function __construct($members) { $this->members = $members } public function handle () { foreach ($this->members $member) { //your logic } }
and if want inject eloquent model job (instead of array) remember can typehint directtly in constructor , , using serializesmodels
trait laravel retrieve you. described in documentation.
Comments
Post a Comment