Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 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 = new stringableObject('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 Expand Up @@ -470,3 +481,20 @@ public function testMultipleSortOrder(): void
$this->assertEquals('Brett Boe', $subset[2]->name);
}
}

/**
* Mockup class to test stringable objects.
*/
class stringableObject implements Stringable {
private string $string;

public function __construct(string $string)
{
$this->string = $string;
}

public function __toString()
{
return $this->string;
}
}