我在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();
失败。
我该如何解决这个问题?