Skip to content

Commit

Permalink
Support database expressions as custom limit columns
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Feb 10, 2023
1 parent cab2da7 commit defcb62
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Traits/BuildsGroupLimitQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ public function get($columns = ['*'])
return $items;
}

$column = last(explode('.', $this->groupLimit['column']));
$keys = ['laravel_row'];

$keys = [
'laravel_row',
'@laravel_partition := '.$this->grammar->wrap($column),
'@laravel_partition := '.$this->grammar->wrap('pivot_'.$column),
];
if (is_string($this->groupLimit['column'])) {
$column = last(explode('.', $this->groupLimit['column']));

$keys[] = '@laravel_partition := '.$this->grammar->wrap($column);
$keys[] = '@laravel_partition := '.$this->grammar->wrap('pivot_'.$column);
}

foreach ($items as $item) {
unset($item->{$keys[0]}, $item->{$keys[1]}, $item->{$keys[2]});
foreach ($keys as $key) {
unset($item->$key);
}
}

return $items;
Expand Down

0 comments on commit defcb62

Please sign in to comment.