Reputation:
I have a messages
table in my database and the query I want to perform is:
$sql = 'SELECT * FROM MESSAGES WHERE sender_id = ' . $id. ' OR receiver_id = '. $id;
That is what I am looking for. So, how do I do the very same thing in laravel?
I searched in the laravel documentation and found something like SQL raw statements
but I guess it can be vulnerable to SQL attacks, so how do I do it safely and sweetly?
Upvotes: 1
Views: 66
Reputation: 8548
Your may use the following code to solve your problem.
DB::table('messages')
->where('sender_id', $id)
->orWhere('reciever_id', $id)
->get();
Upvotes: 0
Reputation: 1131
This is is the "Laravel Way" of building the raw query you've got.
DB::table('messages')->where('sender_id', '=', $id)
->orWhere('reciever_id', '=', $id)->get();
Upvotes: 1