2

Hello I have 5 records on cards table, and when I use not in on phpmyadmin it's working

SELECT id FROM cards WHERE id NOT IN (1,2)

enter image description here

but when I used not in on Laravel it's not working, and it only bind on 1st

$test = "1,2";

$cards = DB::SELECT(DB::RAW("SELECT id FROM cards WHERE id NOT IN (:exception)"), ['exception'=>$test]);

echo "<pre>";
var_dump($cards);
echo "</pre>";

enter image description here

I'm using this guide to avoid SQL Injection: http://fideloper.com/laravel-raw-queries

0

1 Answer 1

3
DB::table('cards')->whereRaw('id NOT IN(".$test.")')->get();

Please try this code instead.

Sign up to request clarification or add additional context in comments.

8 Comments

I need to use DB::RAW() cause I have a long query, this is just a sample to make question easier to understand.
$cards = DB::SELECT(DB::RAW("SELECT id FROM cards WHERE id NOT IN (".$test.")")); this one ?
I need to use fideloper.com/laravel-raw-queries to avoid SQL Injection.
ok actually the problem is with commas , system is assuming single character $test = "1"; instead of $test = "1,2";
i think no problem if you have long query then also you have to use DB::table with in between Raw() where it is needed i dnt think so this method fails
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.