I have a generic function that gives me general queries, for example:
class Model extends Eloquent {
public static function get_queryset(){
$queryset = self::where('foo','=','bar');
return $queryset->orderBy('somefield');
}
}
This function is used throughout my project, but at a certain point I need to use this set of queries, but change ORDER BY, like this:
public static function get_specific_field(){
return self::get_queryset()->select('singlefield')->orderBy('singlefield');
}
If I run this code, ORDER BY will simply add to the previous one and create an invalid query since "somefield" is not in the SELECTed fields. those.:
SELECT singlefield FROM table ORDER BY somefield ASC, singlefield ASC
How to clear orderBy so that I can just reuse the queries?
source
share