diff --git a/src/Query/Builder.php b/src/Query/Builder.php index f83bce3e2..3c60a071f 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -512,7 +512,7 @@ public function orderBy($column, $direction = 'asc') if ($column == 'natural') { $this->orders['$natural'] = $direction; } else { - $this->orders[$column] = $direction; + $this->orders[(string) $column] = $direction; } return $this; diff --git a/tests/QueryTest.php b/tests/QueryTest.php index b2716e178..c85cd2a21 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -239,6 +239,17 @@ public function testOrder(): void $this->assertEquals(35, $user->age); } + public function testStringableOrder(): void + { + $age = str('age'); + + $user = User::whereNotNull('age')->orderBy($age, 'asc')->first(); + $this->assertEquals(13, $user->age); + + $user = User::whereNotNull('age')->orderBy($age, 'desc')->first(); + $this->assertEquals(37, $user->age); + } + public function testGroupBy(): void { $users = User::groupBy('title')->get();