Skip to content

Commit 5be6d91

Browse files
[12.x] Fix use array_first and array_last (#56820)
* Update Connection.php * Update MorphOneOrMany.php * Update Builder.php * Update Grammar.php * Update SqlServerGrammar.php * Update Grammar.php * Update Fluent.php
1 parent 2b99f17 commit 5be6d91

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public function scalar($query, $bindings = [], $useReadPdo = true)
369369
throw new MultipleColumnsSelectedException;
370370
}
371371

372-
return array_last($record);
372+
return array_first($record);
373373
}
374374

375375
/**

src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function setForeignAttributesForCreate(Model $model)
116116
*/
117117
public function upsert(array $values, $uniqueBy, $update = null)
118118
{
119-
if (! empty($values) && ! is_array(array_last($values))) {
119+
if (! empty($values) && ! is_array(array_first($values))) {
120120
$values = [$values];
121121
}
122122

src/Illuminate/Database/Query/Builder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,7 +3158,7 @@ public function soleValue($column)
31583158
{
31593159
$result = (array) $this->sole([$column]);
31603160

3161-
return array_last($result);
3161+
return array_first($result);
31623162
}
31633163

31643164
/**
@@ -3781,7 +3781,7 @@ public function insert(array $values)
37813781
return true;
37823782
}
37833783

3784-
if (! is_array(array_last($values))) {
3784+
if (! is_array(array_first($values))) {
37853785
$values = [$values];
37863786
}
37873787

@@ -3818,7 +3818,7 @@ public function insertOrIgnore(array $values)
38183818
return 0;
38193819
}
38203820

3821-
if (! is_array(array_last($values))) {
3821+
if (! is_array(array_first($values))) {
38223822
$values = [$values];
38233823
} else {
38243824
foreach ($values as $key => $value) {
@@ -3976,7 +3976,7 @@ public function upsert(array $values, array|string $uniqueBy, ?array $update = n
39763976
return (int) $this->insert($values);
39773977
}
39783978

3979-
if (! is_array(array_last($values))) {
3979+
if (! is_array(array_first($values))) {
39803980
$values = [$values];
39813981
} else {
39823982
foreach ($values as $key => $value) {
@@ -3987,7 +3987,7 @@ public function upsert(array $values, array|string $uniqueBy, ?array $update = n
39873987
}
39883988

39893989
if (is_null($update)) {
3990-
$update = array_keys(array_last($values));
3990+
$update = array_keys(array_first($values));
39913991
}
39923992

39933993
$this->applyBeforeQueryCallbacks();

src/Illuminate/Database/Query/Grammars/Grammar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,11 +1186,11 @@ public function compileInsert(Builder $query, array $values)
11861186
return "insert into {$table} default values";
11871187
}
11881188

1189-
if (! is_array(array_last($values))) {
1189+
if (! is_array(array_first($values))) {
11901190
$values = [$values];
11911191
}
11921192

1193-
$columns = $this->columnize(array_keys(array_last($values)));
1193+
$columns = $this->columnize(array_keys(array_first($values)));
11941194

11951195
// We need to build a list of parameter place-holders of values that are bound
11961196
// to the query. Each insert should have the exact same number of parameter

src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ protected function compileUpdateWithJoins(Builder $query, $table, $columns, $whe
415415
*/
416416
public function compileUpsert(Builder $query, array $values, array $uniqueBy, array $update)
417417
{
418-
$columns = $this->columnize(array_keys(array_last($values)));
418+
$columns = $this->columnize(array_keys(array_first($values)));
419419

420420
$sql = 'merge '.$this->wrapTable($query->from).' ';
421421

src/Illuminate/Database/Schema/Grammars/Grammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ protected function getCommandByName(Blueprint $blueprint, $name)
387387
$commands = $this->getCommandsByName($blueprint, $name);
388388

389389
if (count($commands) > 0) {
390-
return array_last($commands);
390+
return array_first($commands);
391391
}
392392
}
393393

src/Illuminate/Support/Fluent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function __call($method, $parameters)
301301
return $this->macroCall($method, $parameters);
302302
}
303303

304-
$this->attributes[$method] = count($parameters) > 0 ? array_last($parameters) : true;
304+
$this->attributes[$method] = count($parameters) > 0 ? array_first($parameters) : true;
305305

306306
return $this;
307307
}

0 commit comments

Comments
 (0)