I have been unable to find an answer in the Laravel docs. I am using Laravel 8.
I have a conversations table with two fields that I want to check: sender_id and receiver_id.
Table:
Schema::create('conversations', function (Blueprint $table) {
$table->id();
$table->integer('sender_id');
$table->integer('receiver_id');
$table->timestamps();
});
I want to find out if a conversation between two users already exists. Since a user can be a sender or a receiver, the query must check using AND and OR.
Here's the query in SQL:
SELECT *
FROM `conversations`
WHERE sender_id = 3 AND receiver_id = 6
OR receiver_id = 6 AND sender_id = 3;
Thanks @kevinbui. I'm getting the sender_id and receiver_id values from a form submission and attempting to use $request-> to pass them, but it's throwing an error that request is not defined. I passed it in the function to see if that works, but it threw another error. Apparently, it's not being recognized inside the function. Any idea why?