I guess that 'Job.php' is not related to Queue concept (correct me if I am wrong). From my point of view, your job_step pivot table does not need the user_id because you already have that information through the job.
A good way is to create a model that represents the pivot table JobStep, this comes with extra benefits like dispatch events when a job_step is created or deleted, define computed attributes, relationships, etc.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\User;
class JobStep extends Pivot
{
protected $table = 'job_step';
protected $fillable = ['job_id', 'step_id', //...];
// This is not necessary, just to give an extra point in case you need it
protected $dispatchesEvents = ['created' => YourCustomEvent::class];
public function job(): BelongsTo
{
return $this->belongsTo(Job::class)->with('user');
}
public function user(): User {
return $this->job->user;
}
}
So once this is created you can link this class with the method using() on your belongsToMany Relationship
public function steps()
{
return $this->belongsToMany(Step::class)
->using(JobStep::class)
->withPivot([
'step_id', 'job_id', 'status', 'image_src', 'user_id', 'notes', 'completed_at'
]);
}
// You'll see something similar in the Models retrieved that contains the pivot
App\Models\Step {#4889
//...
pivot: App\Models\JobStep {#4888
step_id: 5193471413587968,
job_id: 5193470755082240,
//...
}
}
//And you can access like this via the many-to-many relationship:
$step->pivot->user()->name
I hope that was clear because many to many relationships can be a bit tricky when you are starting out but once you understand them everything is clear.