File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
src/Jenssegers/Mongodb/Query Expand file tree Collapse file tree 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)
281281 * @param string $direction
282282 * @return Builder
283283 */
284- public function orderBy ($ column , $ direction = ' asc ' )
284+ public function orderBy ($ column , $ direction = null )
285285 {
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+ }
287296
288297 return $ this ;
289298 }
Original file line number Diff line number Diff line change @@ -147,6 +147,9 @@ public function testOrder()
147147
148148 $ user = User::whereNotNull ('age ' )->orderBy ('age ' , 'desc ' )->first ();
149149 $ this ->assertEquals (37 , $ user ->age );
150+
151+ $ user = User::whereNotNull ('age ' )->orderBy ('natural ' )->first ();
152+ $ this ->assertEquals (35 , $ user ->age );
150153 }
151154
152155 public function testGroupBy ()
You can’t perform that action at this time.
0 commit comments