Laravel binding replaces question mark from variable

I have a table of areas, for example:

-----------------------------
id | name        | level
-----------------------------
1  | India       | country
2  | Some?thing  | country

in this table, I added a line with a question mark , and I want to select this line as follows Request in eloquence:

Area::select(*)->where("name","LIKE", "%Some?thing%")
               ->where("level","=","country")->get();

but this does not give a result, because the question mark in the line where the condition is replaced by bindings

generated raw sql:

select * from area where name like %Somecountrything% AND level = ?

but I want it to look like

select * from area where name like %Some?thing% AND level = country
+4
source share
3 answers

Try the following:

Area::whereRaw("name LIKE '%Some?thing%'")
               ->where("level","=","country")->get();

You can embed raw mysql queries in laravel with whereRaw()

+2
source

Use whereRaw()for this

as

DB::table('users')->whereRaw("email LIKE '%Some?thing%'")->get();
Print_r(DB::getQueryLog());

It is displayed as follows:

select * from `abc_users` where email LIKE '%Some?thing%'

Hope this helps!

0

to try ...

Area::select('*') ....

Full code:

Client::select('*')->where("name","LIKE", "%xyz?xyz%")
               ->where("city","=","331")->get();

Conclusion: enter image description here

0
source

Source: https://habr.com/ru/post/1671964/


All Articles