【问题标题】:Laravel queue : Job Serialization of 'Closure' is not allowedLaravel 队列:不允许“闭包”的作业序列化
【发布时间】:2019-01-30 04:58:06
【问题描述】:

我已经尝试解决this和this,最后,他们没有解决我的问题。

我像这样将工作添加到我的队列中

public function successPayment(Request $request){

$command = Command::findOrFail($request->reference);

if($command->state == Command::PENDING){
        $command->state = Command::SUCCESS;
        $command->payed_at = now();

        if(!empty($oldCommandItem = session('renew_command')))
        {
            $commandItem = $command->items()->offers()->get()->first();
            $commandItem->application_id = $oldCommandItem->application->id;
            $commandItem->save();


            $notification = $user->notifications->last();
            $application = $commandItem->application;

            RestoreApplicationJob::dispatch(['application'=>$application, 'notification'=>$notification]);

            $next = route('application.show', $commandItem->application_id);
            session()->forget('renew_command');
        }

        $command->save();
    }
 }

我的工作

class RestoreApplicationJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $datas;

public $tries = 1;


public function __construct($datas)
{
    $this->datas = $datas;
}

public function handle()
{
    try{
        $application = $this->datas['application'];
        $notification = $this->datas['notification'];
        $application->activate();
        $tmp_data = $notification->data;
        $tmp_data['state'] = Opertation::SUCCESS;

        $notification->data = $tmp_data;
        $notification->save();
    }catch(\Exception $e)
    {
        Log::error($e->getMessage());
        Log::error($e->getTraceAsString());

        $tmp_data = $notification->data;
        $tmp_data['state'] = Opertation::FAILED;

        $notification->data = $tmp_data;
        $notification->save();
    }
}

}

我有这个错误:

不允许序列化“闭包”

我检查了很多次,但没有找到任何东西

感谢您的帮助,并为我的英语如此糟糕感到抱歉:)!

【问题讨论】:

    标签: php laravel laravel-5 queue


    【解决方案1】:

    我的问题太疯狂了……

    我只是在 Job 中调用 Opertation 类的 Operation 类。 那个抛出异常...

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      • 2014-04-21
      相关资源
      最近更新 更多