diff --git a/src/FastPaginate.php b/src/FastPaginate.php index 179cd81..0a7948b 100644 --- a/src/FastPaginate.php +++ b/src/FastPaginate.php @@ -125,6 +125,8 @@ public static function getInnerSelectColumns($builder) // is totally reasonable. We'll look for both // quoted and unquoted, as a kindness. // See https://github.com/hammerstonedev/fast-paginate/pull/57 + $column = $column instanceof Expression ? $column->getValue($base->grammar) : $column; + return [ $column, $base->grammar->wrap($column), diff --git a/tests/Integration/BuilderTest.php b/tests/Integration/BuilderTest.php index d90730d..df87dc4 100644 --- a/tests/Integration/BuilderTest.php +++ b/tests/Integration/BuilderTest.php @@ -235,6 +235,21 @@ public function unquoted_selects_are_preserved_if_used_in_order_by() ); } + /** @test */ + public function using_expressions_for_order_work() + { + $queries = $this->withQueriesLogged(function () use (&$results) { + $results = User::query()->selectRaw('(select 1) as computed_column')->orderBy( + User::query()->select('name')->orderBy('name')->limit(1)->getQuery() + )->fastPaginate(); + }); + + $this->assertEquals( + 'select `users`.`id` from `users` order by (select `name` from `users` order by `name` asc limit 1) asc limit 15 offset 0', + $queries[1]['query'] + ); + } + /** @test */ public function havings_defer() {