mysql functions in query builder in laravel

2020-07-06 08:48发布

I want to use the function in MySQL like convert(name use gbk).

How can I use this with Laravel's query builder with?

I tried ->orderBy(convert(name using gbk)) but it doesnt work.

1条回答
一夜七次
2楼-- · 2020-07-06 09:06

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)'))

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.

查看更多
登录 后发表回答