Undefined property: Illuminate\Queue\Jobs\BeanstalkdJob:: $name

那年仲夏 提交于 2019-12-11 10:26:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!