I'm trying to sort results by column value but it doesn't work
$users = Comment::select([
'id',
'comment',
'user_name',
'product_id',
'rating',
'country',
'status',
'pin',
'created_at',
])->where('shop_name',$shop)->where('product_id', $id)->with('images')->orderByRaw("IF(product_url = 'customer') DESC")->orderByRaw("product_url = manually ASC")->orderBy('pin', 'desc')->orderBy('rating', 'desc')->with('pages')->get();
I added this code
->orderByRaw("IF(product_url = 'customer') DESC")
and I get this error
"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') DESC, product_url = manually ASC,
pindesc,ratingdesc' at line 1 (SQL: selectid,comment,user_name,product_id,rating,country,status,pin,created_atfromcommentswhereshop_name= andproduct_id= order by IF(product_url = 'customer') DESC, product_url = manually ASC,pindesc,ratingdesc)
IFresult as a computed column, then order on that. - tadman