query nampilin user kalo udah chatan

Permisi gan ane mau tanya gimana ya query ini jadi kalo misalkan usernya belom pernah chatan ga bakal tampil, kalo udah pernah chatan baru bisa tampil, terima kasih

public function chatan()
    {
        $user = DB::select("select users.id, users.nama_depan,users.nama_belakang, users.gambar, users.email, count(is_read) as unread
        from users LEFT JOIN messages ON users.id = messages.from and is_read = 0 and messages.to = " . Auth::id() . "
        where users.id != " . Auth::id() . " group by users.id, users.nama_depan,users.nama_belakang, users.gambar, .users.email");
        return view('home', ['user' => $user]);
    }
    public function getMessage($user_id)
    {

        $my_id = Auth::id();
        Message::where(['from' => $user_id, 'to' => $my_id])->update(['is_read' => 1]);
        $messages = Message::where(function ($query) use ($user_id, $my_id) {
            $query->where('from', $my_id)->where('to', $user_id);
        })->orwhere(function ($query) use ($user_id, $my_id) {
            $query->where('from', $user_id)->where('to', $my_id);
        })->get();

        return view('messages.index', ['messages' => $messages]);
    }
avatar werich1

Ditanyakan oleh @werich1

85 Kontribusi 6 Poin

Login untuk menanggapi


Jawaban

Belum ada Jawaban, jadi yang pertama

Login untuk gabung berdiskusi