回答編集履歴
1
frameworkの処理を追記
answer
CHANGED
@@ -5,4 +5,41 @@
|
|
5
5
|
['email' => 'taylor@example.com', 'votes' => 0],
|
6
6
|
['email' => 'dayle@example.com', 'votes' => 0]
|
7
7
|
]);
|
8
|
+
```
|
9
|
+
> framework側のInsertメソッド(スイマセン。Ver 5.3ですが、たぶん変わらないはず)
|
10
|
+
```PHP
|
11
|
+
/**
|
12
|
+
* Compile an insert statement into SQL.
|
13
|
+
*
|
14
|
+
* @param \Illuminate\Database\Query\Builder $query
|
15
|
+
* @param array $values
|
16
|
+
* @return string
|
17
|
+
*/
|
18
|
+
public function compileInsert(Builder $query, array $values)
|
19
|
+
{
|
20
|
+
// Essentially we will force every insert to be treated as a batch insert which
|
21
|
+
// simply makes creating the SQL easier for us since we can utilize the same
|
22
|
+
// basic routine regardless of an amount of records given to us to insert.
|
23
|
+
$table = $this->wrapTable($query->from);
|
24
|
+
|
25
|
+
if (! is_array(reset($values))) {
|
26
|
+
$values = [$values];
|
27
|
+
}
|
28
|
+
|
29
|
+
$columns = $this->columnize(array_keys(reset($values)));
|
30
|
+
|
31
|
+
// We need to build a list of parameter place-holders of values that are bound
|
32
|
+
// to the query. Each insert should have the exact same amount of parameter
|
33
|
+
// bindings so we will loop through the record and parameterize them all.
|
34
|
+
$parameters = [];
|
35
|
+
|
36
|
+
foreach ($values as $record) {
|
37
|
+
$parameters[] = '('.$this->parameterize($record).')';
|
38
|
+
}
|
39
|
+
|
40
|
+
$parameters = implode(', ', $parameters);
|
41
|
+
//ここ!
|
42
|
+
return "insert into $table ($columns) values $parameters";
|
43
|
+
}
|
44
|
+
|
8
45
|
```
|