Код: Выделить всё
public function getConversationsAttribute()
{
$results = DB::select('SELECT * FROM conversation_user WHERE user_id = ?', [$this->id]);
$conversations = array();
foreach($results as $result){
$conversation = Conversation::find($result->conversation_id);
array_push($conversations, $conversation);
}
return $conversations;
}
т. е. общие результаты между $userA->conversations и $userB->conversations
Я представляю себе оператор UNION для дубликатов это то, что требуется.
Что такое:
[*]Решение MySQL
[*]Красноречивое решение
Подробнее здесь: https://stackoverflow.com/questions/661 ... ollections