简体   繁体   中英

mysql functions in query builder in laravel

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM