File tree 2 files changed +14
-2
lines changed
src/Jenssegers/Mongodb/Query
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -281,9 +281,18 @@ public function distinct($column = false)
281
281
* @param string $direction
282
282
* @return Builder
283
283
*/
284
- public function orderBy ($ column , $ direction = ' asc ' )
284
+ public function orderBy ($ column , $ direction = null )
285
285
{
286
- $ this ->orders [$ column ] = (strtolower ($ direction ) == 'asc ' ? 1 : -1 );
286
+ if (is_null ($ direction ) && $ column == 'natural ' )
287
+ {
288
+ $ this ->orders ['$natural ' ] = 1 ;
289
+ }
290
+ else
291
+ {
292
+ $ direction = $ direction ?: 'asc ' ;
293
+
294
+ $ this ->orders [$ column ] = (strtolower ($ direction ) == 'asc ' ? 1 : -1 );
295
+ }
287
296
288
297
return $ this ;
289
298
}
Original file line number Diff line number Diff line change @@ -147,6 +147,9 @@ public function testOrder()
147
147
148
148
$ user = User::whereNotNull ('age ' )->orderBy ('age ' , 'desc ' )->first ();
149
149
$ this ->assertEquals (37 , $ user ->age );
150
+
151
+ $ user = User::whereNotNull ('age ' )->orderBy ('natural ' )->first ();
152
+ $ this ->assertEquals (35 , $ user ->age );
150
153
}
151
154
152
155
public function testGroupBy ()
You can’t perform that action at this time.
0 commit comments