Skip to content

Commit e5accca

Browse files
committed
withSort() method and orderBy changes
1 parent 9c90f2e commit e5accca

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/Eloquent/Docs/ModelDocs.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
* @method static $this whereNotNestedObject(string $column, Callable $callback, string $scoreType = 'avg')
5656
* @method static $this firstOrCreate(array $attributes, array $values = [])
5757
* @method static $this firstOrCreateWithoutRefresh(array $attributes, array $values = [])
58-
* @method static $this orderBy(string $column, string $direction = 'asc', string $mode = null, array $missing = '_last')
59-
* @method static $this orderByDesc(string $column, string $mode = null, array $missing = '_last')
58+
* @method static $this orderBy(string $column, string $direction = 'asc')
59+
* @method static $this orderByDesc(string $column)
60+
* @method static $this withSort(string $column, string $key, mixed $value)
6061
* @method static $this orderByGeo(string $column, array $pin, $direction = 'asc', $unit = 'km', $mode = null, $type = 'arc')
6162
* @method static $this orderByGeoDesc(string $column, array $pin, $unit = 'km', $mode = null, $type = 'arc')
6263
* @method static $this orderByNested(string $column, string $direction = 'asc', string $mode = null)

src/Query/Builder.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function aggregate($function, $columns = []): mixed
410410

411411
if (isset($results[0])) {
412412
$result = (array) $results[0];
413-
$esResult = new ElasticResult();
413+
$esResult = new ElasticResult;
414414
$esResult->setQueryMeta($results->getQueryMeta());
415415
$esResult->setValue($result['aggregate']);
416416

@@ -813,29 +813,41 @@ public function whereTimestamp($column, $operator = null, $value = null, $boolea
813813
/**
814814
* {@inheritDoc}
815815
*/
816-
public function orderByDesc($column, $mode = null, $missing = null): static
816+
public function orderByDesc($column): static
817817
{
818-
return $this->orderBy($column, 'desc', $mode, $missing);
818+
return $this->orderBy($column, 'desc');
819819
}
820820

821821
/**
822822
* {@inheritdoc}
823823
*/
824-
public function orderBy($column, $direction = 'asc', $mode = null, $missing = null): static
824+
public function orderBy($column, $direction = 'asc'): static
825825
{
826826
if (is_string($direction)) {
827827
$direction = (strtolower($direction) == 'asc' ? 'asc' : 'desc');
828828
}
829829

830830
$this->orders[$column] = [
831831
'order' => $direction,
832-
'mode' => $mode,
833-
'missing' => $missing,
834832
];
835833

836834
return $this;
837835
}
838836

837+
/**
838+
* Including outlier sort functions
839+
*
840+
* @return $this
841+
*/
842+
public function withSort(string $column, string $key, mixed $value): static
843+
{
844+
$currentColOrder = $this->orders[$column] ?? [];
845+
$currentColOrder[$key] = $value;
846+
$this->orders[$column] = $currentColOrder;
847+
848+
return $this;
849+
}
850+
839851
/**
840852
* @param $unit @values: 'km', 'mi', 'm', 'ft'
841853
* @param $mode @values: 'min', 'max', 'avg', 'sum'

0 commit comments

Comments
 (0)