Skip to content

Commit

Permalink
Merge pull request #2420 from apeisa/fix/stringable-sort
Browse files Browse the repository at this point in the history
[3.9] Fix/stringable sort
  • Loading branch information
KarenEtheridg authored Feb 23, 2024
2 parents cf07c5a + eee8a18 commit e0bc3ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e0bc3ff

Please sign in to comment.