Skip to content

Commit

Permalink
Merge pull request #1 from morphsteve/fix-first-last
Browse files Browse the repository at this point in the history
Determine first and last resource correctly for customised sort queries.
  • Loading branch information
michielkempen authored Sep 20, 2018
2 parents 6f365a5 + e9be981 commit b845a23
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/OrderField.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ class OrderField extends Field
*/
protected function resolveAttribute($resource, $attribute)
{
$orderField = $resource->sortable['order_column_name'];

$first = $resource->newQuery()->orderBy($orderField, 'asc')->first();
$last = $resource->newQuery()->orderBy($orderField, 'desc')->first();
$first = $resource->buildSortQuery()->ordered()->first();
$last = $resource->buildSortQuery()->ordered('desc')->first();

$this->withMeta([
'first' => is_null($first) ? null : $first->id,
Expand Down

0 comments on commit b845a23

Please sign in to comment.