Laravel get all conversations by the column user_id and every conversation should get all the messages

  laravel

i have a table Conversations
Conversations has many conversations

and i have Messages Table
Messages table has many messages
Messages table contains a row where every message in the table has a row conversation_id
this indicate that every message belong to a conversation

im able to use

<?php

namespace App;

use IlluminateDatabaseEloquentModel;

 /**
 * Get the Messages for the Conversation chat.
 */
public function messages()
{
    return $this->hasMany('AppMessage');
}

in the controller im able to get all messages that belongs to that conversation (1)

$messages = AppConversation::find(1)->messages ;

what i want is i want to get all conversations by the column user_id and every conversation should get all the messages?

how do i do this please i dont know what should i use

Source: Laravel

Leave a Reply