get a list of users who I have contacted or they have contacted me

  laravel, php

I’m working on messaging application (internal) and I would like to get a list of users who have contacted or I have contacted, just like facebook inbox ( on the left you see a list of users who contacted you or you have contacted )

I tried a lot but I couldn’t success, what kind of relations I should use to get what I’m looking for, 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();
        });

Source: Ask PHP

LEAVE A COMMENT