如何从Laravel工作班级访问有效负载?访问Laravel Queued Job的有效负载数据
我曾尝试:
<?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
....
我这些从作业类。但payload()和getRawBody()均返回Call to undefined method
。
其他方法from that class do work - 例如,$this->release(1)
,所以我不知道,如果不$this
指实际的作业类。
我正在使用Redis队列驱动程序,使用Laravel 5.4。
你希望从payload()方法中获得什么?通常情况下,您会通过构造函数传递作业所需的数据,就像您使用“PDF”类所做的那样。 – James