Skip to content

Commit 71aff96

Browse files
committed
fix array
1 parent 672d152 commit 71aff96

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/LaravelSubQuery.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ public function withAvg($relations)
6262
public function orderByRelation($relations, $orderType = 'desc', $type = 'max')
6363
{
6464
if (is_array($relations)) {
65-
$orderType = $relations[0];
66-
$type = $relations[1];
65+
$orderType = isset($relations[0]) ? $relations[0] : $orderType;
66+
$type = isset($relations[1]) ? $relations[1] : $type;
6767
unset($relations[0], $relations[1]);
6868
}
69-
if (! strpos($relations, ':')) {
70-
return $this->orderBy($relations, $orderType);
69+
70+
$column = is_array($relations) ? array_key_first($relations) : $relations;
71+
if (! strpos($column, ':')) {
72+
return $this->orderBy($column, $orderType);
7173
}
7274

7375
return $this->withSubQuery($relations, $type, $orderType);

0 commit comments

Comments
 (0)