Laravel绑定替换变量中的问号

时间:2017-03-10 07:04:39

标签: php laravel laravel-5 laravel-eloquent

我有区域表:

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

在此表中,我添加了一行问号,我想选择该行如下 用口才查询:

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

但是这不会给出结果,因为在条件替换为绑定的字符串中的问号

生成的原始sql是:

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

但我希望它像

select * from area where name like %Some?thing% AND level = country

3 个答案:

答案 0 :(得分:3)

试试这个:

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

您可以在whereRaw()

的帮助下将原始mysql查询注入laravel

答案 1 :(得分:1)

将<{1}}用于此

whereRaw()

输出如下:

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

希望这有帮助!

答案 2 :(得分:1)

尝试...

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

完整代码:

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

输出: enter image description here