php - Laravel eloquent, how to order custom sortby -


i have following code works fine:

$products = product::like($search)->wherein('id', $request->input('product_ids'))->skip($offset)->take($limit)->get(array('products.*'))->sortby(function($product) use ($sort_order) {     $number = (isset($sort_order[$product->id])) ? $sort_order[$product->id] : 0;     return $number; }); 

this returns items in ascending order, how specify whether want sortby return products in ascending or descending order?

//$order contains either 'asc' or 'desc' $products = product::like($search)->wherein('id', $request->input('product_ids'))->skip($offset)->take($limit)->get(array('products.*'))->sortby(function($product) use ($sort_order, $direction) {     $number = (isset($sort_order[$product->id])) ? $sort_order[$product->id] : 0;     return ($direction == 'asc') ? $number : -$number; }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -