问题
I'm using beanstalkd with Laravel to queue some tasks but I'm having trouble to send data to the function that handles the queue , Here is my code
//Where I call the function
$object_st = new stdClass();
$object_st->Person_id = 2 ;
//If I do this: echo($object_st->Person_id); , I get 2
Queue::push('My_Queue_Class@My_Queue_Function', $object_st );
And the function that handle the queue is the following
public function My_Queue_Function( $Data )
{
$Person_id = $Data->Person_id; //This generate the error
//Other code
}
The error says:
[ErrorException]
Undefined property: Illuminate\Queue\Jobs\BeanstalkdJob::$Person_id
回答1:
The way queues work in 4.2 is different than 5; the first argument in the function that handles the queue task is actually a queue job instance, the second argument would be your data:
class SendEmail {
public function fire($job, $data)
{
//
}
}
As per example from the documentation.
Your code would therefor need to allow the first argument:
public function My_Queue_Function( $job, $Data )
{
$Person_id = $Data['Person_id'];
//Other code
}
来源:https://stackoverflow.com/questions/33917028/undefined-property-illuminate-queue-jobs-beanstalkdjob-name