Fetch related users in Laravel

  laravel, php

I’m working on chat application, I would like to fetch related users (users with who I have a conversation already) who contacted me or who I have already contacted

I have two models, User, Message :
This is my migration :

Schema::create('messages', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('receiver_id');

            $table->foreign('user_id')->references('id')->on('users');
            $table->foreign('receiver_id')->references('id')->on('users');

            $table->text('message')->nullable();
            $table->timestamps();
        });

What kind of relations I do need, I need a help please

Source: Ask PHP

LEAVE A COMMENT