Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

asoftware's avatar

Access an Eloquent Model from Extra Columns on Pivot Table

I have a many to many relationship setup with 3 tables... Call, User, and Call_User as the pivot table. I have added additional columns called status_id in the pivot table with the hopes that I could access the Status model via that new column, but I cannot figure out how to do an eloquent relationship off the pivot table.

I am able to get the pivot table object, but I cannot figure out how to get to the relationship of that additional column on the pivot table...

@foreach($call->users as $user) $user->pivot @endforeach

$user->pivot gives the the row I am looking for in the Call_User table, but I want to then get to the Status model via that status_id of the Call_User pivot table.

I tried the below, but it just returns null...

@foreach($call->users as $user) $user->pivot->status @endforeach

Is it possible to access a model off of a pivot table with an eloquent relationship?

0 likes
2 replies
CorvS's avatar

You could do a workaround and create a UserCalls model for your pivot table, that has a belongs-to-one status() relationship. Then get all records for a certain call

$userCalls = UserCalls::with('status')->where('call_id', $callId)->get();
...
@foreach($userCalls as $userCall)
    {{ $userCall->status->name }}
@endforeach

Please or to participate in this conversation.