I'm not sure what you're asking.
You can add withPivot('chat_room') to the original query to have it included with the connections.
Hi, community please, I am writing my code got this
$user->connections; // user have connections and get this
[
{
id: 2,
name: "pepote",
email: "[email protected]",
email_verified_at: null,
created_at: "2020-04-13T02:21:46.000000Z",
updated_at: "2020-04-13T02:21:46.000000Z",
pivot: {
user_id: 1,
connect_id: 2,
show: 1,
chat_room: "1GFwjj92",
created_at: "2020-04-14T17:19:06.000000Z",
updated_at: "2020-04-14T17:19:06.000000Z"
}
}
]
so yes the user has at this moment ONE connection, if I want to just get the chat room I have to write this code:
return $myConnections->first()->pivot->chat_room;
I don't want to mention the PIVOT it's there another way to call this???? Thanks a lot in advance, got a better answer!
Alternatively you can make a Model for the actual pivot itself, and write a relation that just returns the pivot. It's up to you.
Please or to participate in this conversation.