[英]Convert sql query to eloquent
I'm trying to convert a query to a Laravel query but when I use raw method
I can't make it work. 我正在尝试将查询转换为Laravel查询,但是当我使用
raw method
我无法使其工作。
My query: 我的查询:
SELECT * FROM leagues
WHERE SOUNDEX(name)
LIKE CONCAT('%',SUBSTRING(SOUNDEX('Eng. Premier League'),5),'%');
I couldn't find any docs online that answer me. 我在网上找不到能回答我的任何文档。
You can use WhereRaw()
to conver this query to Laravel Query Builder. 您可以使用
WhereRaw()
将查询转换为Laravel查询生成器。
DB::table('leagues')
->whereRaw("SOUNDEX(name)
LIKE CONCAT('%',SUBSTRING(SOUNDEX('Eng. Premier League'),5),'%')");
if you don't prefer WhereRaw()
then you have to use DB::raw()
in your Conditions 如果您不喜欢
WhereRaw()
则必须在条件中使用DB::raw()
DB::table('leagues')
->where( DB::raw('SOUNDEX(name)'), 'LIKE', DB::raw("CONCAT('%',SUBSTRING(SOUNDEX('Eng. Premier League'),5),'%')") );
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.