Good, so you want to keep the job history in the queue / processed jobs, right.
There is no built-in support for customizing database fields.
See:
https://github.com/laravel/framework/blob/7212b1e9620c36bf806e444f6931cf5f379c68ff/src/Illuminate/Queue/DatabaseQueue.php#L170

As far as I understand, this behavior is intended because you should not be linked to the source table of "jobs". It was designed for stateless work. This means that the work record is deleted immediately after its processing.
If you want to keep track of your assignments (e.g. history), you can simply create a new Eloquent model and pass it to the assignment designer. This is useful for synchronizing the original work and your story.
Ok, let's start coding, right?
Create a new migration by typing:
php artisan does: create_jobs_history_table migration
Now open this migration and add the following column types.
database / migration / xyz_create_jobs_history_table :
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateJobsHistoryTable extends Migration { public function up() { Schema::create('jobs_history', function(Blueprint $table) { $table->bigIncrements('id'); $table->unsignedInteger('user_id'); $table->string('job', 40); $table->integer('status')->default(0); $table->timestamps(); if (Schema::hasColumn('users', 'id')) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); } }); } public function down() { Schema::disableForeignKeyConstraints(); Schema::dropIfExists('jobs_history'); Schema::enableForeignKeyConstraints(); } }
Explanation:
As you can see, we have added three new types: user_id , job and status .
User_id refers to the actual user id.
The task field is simply a description / title of the task.
The status field represents the status. 0 = not yet processed, 1 = completed
Now that our migration is ready, let's define a new model for it:
app / JobHistory.php
<?php namespace App; use Illuminate\Database\Eloquent\Model; class JobHistory extends Model { protected $table = 'jobs_history'; protected $hidden = []; }
Cute. Now we can easily interact with our work history in our application.
It is time to create a job. Let's do it with the following code:
app / Jobs / ProvisionUser.php
<?php namespace App\Jobs; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use App\User; use App\JobHistory; class ProvisonUser implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $user; protected $history; public function __construct(User $user, JobHistory $history) { $this->user = $user; $this->history = $history;
Explanation:
Here we have included the User and JobHistory models. In our constructor, we need both models, and we set a new history record.
Actual work is now synchronized with our new story!
Good.
The handle() function is called during job processing. Here we set status 1 as soon as it ends.
And finally, just submit the work to your controller:
<?php namespace App\Http\Controllers; use Carbon\Carbon; use App\User; use App\JobHistory; use App\Jobs\ProvisionUser; class SomeController extends Controller { public function provision() { $user = User::find(1); $job = (new ProvisionUser($user, new JobHistory)) ->delay(Carbon::now()->addMinutes(1)); dispatch($job); return view('provision'); } }
Explanation:
We pass on the existing user and the new task history to the designer. After that we send the deferred work.
Note: the delay is for demonstration purposes only.
Open your database and check your jobs_history table. As soon as your task has been sent, the status of the corresponding history record should be 0. After the worker of the artisan queue has processed the task, the status of the history record should be 1.
I tested this setting with Laravel 5.4 and use the same logic in my application.
Good coding!