[英]mysql functions in query builder in laravel
I want to use the function in MySQL like convert(name use gbk)
. 我想在MySQL中使用像
convert(name use gbk)
这样的函数convert(name use gbk)
。
How can I use this with Laravel's query builder with
? 我如何在Laravel的查询构建器中
with
?
I tried ->orderBy(convert(name using gbk))
but it doesnt work. 我试过
->orderBy(convert(name using gbk))
但它不起作用。
You need to use the Raw function of eloquent. 你需要使用eloquent的Raw函数。
DB::raw(your sql)
In your case, the following query should work: 在您的情况下,以下查询应该工作:
->orderBy(DB::raw('convert(name using gbk)'))
If you want to use raw sql in your where statements, your can use the shortcut function whereRaw()
and for a select the selectRaw()
function. 如果要在where语句中使用原始sql,可以使用快捷函数
whereRaw()
并选择selectRaw()
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.