Mysql functions in query builder in laravel

I want to use a function in MySQL, for example convert(name use gbk) .

How can I use this with the Laravel with query constructor?

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

+6
source share
1 answer

You need to use the eloquent Raw function.

 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, you can use the whereRaw() shortcut function to select the selectRaw() function as selectRaw() .

+14
source

Source: https://habr.com/ru/post/976975/


All Articles