laravel中查询生成器中的mysql函数 [英] mysql functions in query builder in laravel
本文介绍了laravel中查询生成器中的mysql函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在MySQL中使用convert(name use gbk)
之类的功能.
I want to use the function in MySQL like convert(name use gbk)
.
如何与Laravel的查询生成器with
一起使用?
How can I use this with Laravel's query builder with
?
我尝试了->orderBy(convert(name using gbk))
,但是它不起作用.
I tried ->orderBy(convert(name using gbk))
but it doesnt work.
推荐答案
您需要使用雄辩的Raw函数.
You need to use the Raw function of eloquent.
DB::raw(your sql)
在您的情况下,以下查询应该有效:
In your case, the following query should work:
->orderBy(DB::raw('convert(name using gbk)'))
如果要在where语句中使用原始sql,则可以使用快捷功能whereRaw()
,并选择selectRaw()
函数.
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.
这篇关于laravel中查询生成器中的mysql函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文