@php
$messages = DB::table('messages')->get();
@endphp
@foreach ($messages as $msg)
@php
$user = DB::table('users')
->where('id', $msg->sender_id)
->orWhere('id', $msg->receiver_id)
->first();
@endphp
@if ($msg->sender_id == Auth::user()->id)
{{ Auth::user()->name }}
{{ $msg->message }}
@else
{{ $user->name }}
{{ $msg->message }}
@endif
@endforeach