且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

laravel中查询生成器中的mysql函数

更新时间:2023-11-17 13:40:10

您需要使用雄辩的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.