I would like to run this SQL query in Laravel:
select * from CATEGORIE order by ID_CATEGORIE = 1, ID_CATEGORIE ASC
I tried with orderBy("ID_CATEGORY", 1) but it doesn't work, we can only put "ASC" or "DESC" in the orderBy of Laravel.
CodePudding user response:
You need to use raw method orderByRaw.
->orderByRaw('ID_CATEGORY = 1, ID_CATEGORY ASC')
https://laravel.com/docs/8.x/queries#orderbyraw
CodePudding user response:
Try this:
DB::table('CATEGORIE')->orderByRaw('ID_CATEGORY = 1, ID_CATEGORY ASC')
->get();
