Skip to content

Commit 8bd7a9b

Browse files
committed
Merge branch '10.x' into 11.x
# Conflicts: # CHANGELOG.md # src/Illuminate/Database/Eloquent/Factories/Factory.php # src/Illuminate/Database/MySqlConnection.php # src/Illuminate/Database/Query/Processors/MySqlProcessor.php # src/Illuminate/Foundation/Application.php
2 parents 5e5cbc7 + 763b942 commit 8bd7a9b

File tree

6 files changed

+423
-2
lines changed

6 files changed

+423
-2
lines changed

src/Illuminate/Database/Eloquent/Factories/Factory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ public function afterMaking(Closure $callback)
678678
/**
679679
* Add a new "after creating" callback to the model definition.
680680
*
681-
* @param \Closure(TModel): mixed $callback
681+
* @param \Closure(\Illuminate\Database\Eloquent\Model|TModel, \Illuminate\Database\Eloquent\Model|null): mixed $callback
682682
* @return static
683683
*/
684684
public function afterCreating(Closure $callback)

src/Illuminate/Database/Eloquent/Model.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ protected function childRouteBindingRelationshipName($childType)
21342134
/**
21352135
* Retrieve the model for a bound value.
21362136
*
2137-
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation $query
2137+
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Contracts\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\Relation $query
21382138
* @param mixed $value
21392139
* @param string|null $field
21402140
* @return \Illuminate\Contracts\Database\Eloquent\Builder

src/Illuminate/Database/MySqlConnection.php

+46
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
class MySqlConnection extends Connection
1616
{
17+
/**
18+
* The last inserted ID generated by the server.
19+
*
20+
* @var string|int|null
21+
*/
22+
protected $lastInsertId;
23+
1724
/**
1825
* {@inheritdoc}
1926
*/
@@ -22,6 +29,35 @@ public function getDriverTitle()
2229
return $this->isMaria() ? 'MariaDB' : 'MySQL';
2330
}
2431

32+
/**
33+
* Run an insert statement against the database.
34+
*
35+
* @param string $query
36+
* @param array $bindings
37+
* @param string|null $sequence
38+
* @return bool
39+
*/
40+
public function insert($query, $bindings = [], $sequence = null)
41+
{
42+
return $this->run($query, $bindings, function ($query, $bindings) use ($sequence) {
43+
if ($this->pretending()) {
44+
return true;
45+
}
46+
47+
$statement = $this->getPdo()->prepare($query);
48+
49+
$this->bindValues($statement, $this->prepareBindings($bindings));
50+
51+
$this->recordsHaveBeenModified();
52+
53+
$result = $statement->execute();
54+
55+
$this->lastInsertId = $this->getPdo()->lastInsertId($sequence);
56+
57+
return $result;
58+
});
59+
}
60+
2561
/**
2662
* Escape a binary value for safe SQL embedding.
2763
*
@@ -46,6 +82,16 @@ protected function isUniqueConstraintError(Exception $exception)
4682
return boolval(preg_match('#Integrity constraint violation: 1062#i', $exception->getMessage()));
4783
}
4884

85+
/**
86+
* Get the connection's last insert ID.
87+
*
88+
* @return string|int|null
89+
*/
90+
public function getLastInsertId()
91+
{
92+
return $this->lastInsertId;
93+
}
94+
4995
/**
5096
* Determine if the connected database is a MariaDB database.
5197
*

src/Illuminate/Database/Query/Processors/MySqlProcessor.php

+35
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,43 @@
22

33
namespace Illuminate\Database\Query\Processors;
44

5+
use Illuminate\Database\Query\Builder;
6+
57
class MySqlProcessor extends Processor
68
{
9+
/**
10+
* Process the results of a column listing query.
11+
*
12+
* @deprecated Will be removed in a future Laravel version.
13+
*
14+
* @param array $results
15+
* @return array
16+
*/
17+
public function processColumnListing($results)
18+
{
19+
return array_map(function ($result) {
20+
return ((object) $result)->column_name;
21+
}, $results);
22+
}
23+
24+
/**
25+
* Process an "insert get ID" query.
26+
*
27+
* @param \Illuminate\Database\Query\Builder $query
28+
* @param string $sql
29+
* @param array $values
30+
* @param string|null $sequence
31+
* @return int
32+
*/
33+
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
34+
{
35+
$query->getConnection()->insert($sql, $values, $sequence);
36+
37+
$id = $query->getConnection()->getLastInsertId();
38+
39+
return is_numeric($id) ? (int) $id : $id;
40+
}
41+
742
/**
843
* Process the results of a columns query.
944
*

0 commit comments

Comments
 (0)