Hi @riskmate_mw
From the relation documentation Many To Many, subsection Retrieving Intermediate Table Columns
By default, only the model keys will be present on the pivot object. If your pivot table contains extra attributes, you must specify them when defining the relationship
So, in your case, you should declare relation in your Risk model like this:
public function riskstatus()
{
return $this->belongsToMany('App\Riskstatus')->withPivot('user_id')
}
So, you result will looks like
App\Risk::find(3)->riskstatus
=> Illuminate\Database\Eloquent\Collection {#4086
all: [
App\Riskstatus {#4078
id: 4,
name: "Rsik accepted",
created_at: "2020-07-23 19:29:34",
updated_at: "2020-07-23 19:29:34",
pivot: Illuminate\Database\Eloquent\Relations\Pivot {#4083
risk_id: 3,
riskstatus_id: 4,
user_id: <userIdHere>
},
},
],
}
By the way, you still not be able to get user name directly here (by using eager loading). You'll need to search in users table by id manually.
Otherwise, if you want to be able to use eager load for all 3 values, you need to create general table for this relation (not the pivot table) and define appropriaterelations