make the job itself responsible for updating the table or issuing an event, which is then heard by a listener that then updates the jobs table.
You would need to pass the jobs table reference to your queued job.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to keep track of the jobs and save the jobs that are completed in a db table. So that I can then send a user notification. This is my table structure.
Schema::create('job_requests', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->dateTime('request_time');
$table->boolean('completed');
$table->foreign('user_id')->references('id')->on('users');
});
Schema::create('job_request_reports', function (Blueprint $table) {
$table->increments('id');
$table->integer('request_id')->unsigned();
$table->integer('survey_id')->unsigned();
$table->boolean('processed');
$table->foreign('request_id')->references('id')->on('job_requests');
$table->foreign('survey_id')->references('id')->on('surveys');
});
This is where I'm dispatching the jobs and also creating instances of the tables above
if (count($report) > 0) {
$job_request = new JobRequest();
$job_request->user_id = auth()->user()->id;
$job_request->request_time = $now;
$job_request->completed = false;
$job_request->save();
foreach ($report as $item) {
$this->dispatch(new DownloadReport($item));
$request_reports = new JobRequestReport();
$request_reports->request_id = $job_request->id;
$request_reports->survey_id = $item->id;
$request_reports->processed = false;
$request_reports->save();
}
}
My questions is how can I use the Job Events to keep track of when the job was successful? How can I check for this?
Queue::after(function (JobProcessed $event) {
// $event->connectionName
// $event->job
// $event->job->payload()
});
Please or to participate in this conversation.