在Laravel Job之前和之后创建一个新行

时间:2017-02-19 14:18:59

标签: php laravel queue

我在Laravel官方页面上使用与队列页面相同的示例:https://laravel.com/docs/5.3/queues#job-events for AppServiceProvider:

use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;

use App\Models;

[...]

    public function boot()
{
    Queue::before(function (JobProcessing $event) {
      echo "start1";
      $theJobs = new TheJobs;
      $theJobs->test = 'hello';
      echo "start";
      $theJobs->save();
      echo "start3";
    });

    Queue::after(function (JobProcessed $event) {
      $theJobs = new TheJobs;
      $theJobs->save();
    });
}

正如您在队列事件之前和队列事件之后看到的那样,我试图在TheJobs表中创建一个新行,但是$theJobs->save();失败。

我该如何解决这个问题?

0 个答案:

没有答案