File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -512,7 +512,7 @@ public function orderBy($column, $direction = 'asc')
512512 if ($ column == 'natural ' ) {
513513 $ this ->orders ['$natural ' ] = $ direction ;
514514 } else {
515- $ this ->orders [$ column ] = $ direction ;
515+ $ this ->orders [( string ) $ column ] = $ direction ;
516516 }
517517
518518 return $ this ;
Original file line number Diff line number Diff line change @@ -239,6 +239,17 @@ public function testOrder(): void
239239 $ this ->assertEquals (35 , $ user ->age );
240240 }
241241
242+ public function testStringableOrder (): void
243+ {
244+ $ age = new stringableObject ("age " );
245+
246+ $ user = User::whereNotNull ('age ' )->orderBy ($ age , 'asc ' )->first ();
247+ $ this ->assertEquals (13 , $ user ->age );
248+
249+ $ user = User::whereNotNull ('age ' )->orderBy ($ age , 'desc ' )->first ();
250+ $ this ->assertEquals (37 , $ user ->age );
251+ }
252+
242253 public function testGroupBy (): void
243254 {
244255 $ users = User::groupBy ('title ' )->get ();
@@ -470,3 +481,21 @@ public function testMultipleSortOrder(): void
470481 $ this ->assertEquals ('Brett Boe ' , $ subset [2 ]->name );
471482 }
472483}
484+
485+ /**
486+ * Mockup class to test stringable objects
487+ */
488+ class stringableObject implements Stringable {
489+
490+ private $ string ;
491+
492+ public function __construct ($ string )
493+ {
494+ $ this ->string = $ string ;
495+ }
496+
497+ public function __toString ()
498+ {
499+ return $ this ->string ;
500+ }
501+ }
You can’t perform that action at this time.
0 commit comments