joining third table on eloquent pivot’s extra column

i have three tables:

users
id, name

order
id, date

status
id, name

and defined pivot table as:

order_user
order_id, status_id, user_id, created_at

so “user_id” is an extra column in pivot.

My Order model has:

public function statuses(){
    return $this->belongsToMany('Status')->withPivot('user_id')->withTimestamps(); 
    }

i can acces user id via:

Order::find(1)->statuses->pivot->user_id

but cannot figure how to get user “name“?

can i somehow “LEFT JOIN” user table in Order model’s “statuses()” method return?

thanks!
Y


Source: laravel

Leave a Reply