Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql functions in query builder in laravel

Tags:

php

mysql

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.

like image 541
TigerWhite Avatar asked Oct 20 '14 12:10

TigerWhite


1 Answers

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.

like image 130
Needpoule Avatar answered Sep 20 '22 02:09

Needpoule