调用int上的成员函数delay()

问题描述 投票:0回答:1

使用 Laravel,如何在导入 Excel 后 5 分钟后收到短信?

只有导入 Excel 后才会收到短信。

我希望 5 分钟后收到短信。

public function import(Request $request)
{
    Excel::import(new OtherImport, $request->file('file')->store('temp'));
    $delay = now()->addMinutes(5);
    Bus::dispatch(new SendSmsJob())->delay($delay);
    return back();
}

我收到此错误。

调用int上的成员函数delay()

excel laravel sms
1个回答
0
投票

您遇到的错误是因为在

delay()
的结果上调用
Bus::dispatch(new SendSmsJob())
方法,该结果是一个整数(调度的作业的 ID),而不是作业实例。

在 Laravel 中,您应该在分派之前将

delay()
方法直接链接到作业实例。

public function import(Request $request)
{
    Excel::import(new OtherImport, $request->file('file')->store('temp'));
    $delay = now()->addMinutes(5);
    $job = (new SendSmsJob())->delay($delay);
    Bus::dispatch($job);

    return back();
}
© www.soinside.com 2019 - 2024. All rights reserved.