【发布时间】:2017-05-04 13:59:36
【问题描述】:
如何从 Laravel 作业类中访问有效负载?
我试过了:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\PDF;
class ProcessConversion implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $pdf;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(PDF $pdf)
{
$this->pdf = $pdf;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$payload = $this->payload(); //undefined method
$payload = $this->payload; //undefined property
$payload = json_decode($this->getRawBody(), true); //undefined method
....
我从 Job 课程中得到这些。但是payload() 和getRawBody() 都返回Call to undefined method。
其他方法from that class do work - 例如$this->release(1),所以我不确定$this 是否指的是实际的作业类。
我正在使用 Redis 队列驱动程序,使用 Laravel 5.4。
【问题讨论】:
-
您希望从
payload()方法中得到什么?通常,您会通过构造函数传递作业所需的数据,就像您对PDF类所做的那样。