回答編集履歴

1

frameworkの処理を追記

2017/06/27 07:27

投稿

motuo
motuo

スコア3027

test CHANGED
@@ -13,3 +13,77 @@
13
13
  ]);
14
14
 
15
15
  ```
16
+
17
+ > framework側のInsertメソッド(スイマセン。Ver 5.3ですが、たぶん変わらないはず)
18
+
19
+ ```PHP
20
+
21
+ /**
22
+
23
+ * Compile an insert statement into SQL.
24
+
25
+ *
26
+
27
+ * @param \Illuminate\Database\Query\Builder $query
28
+
29
+ * @param array $values
30
+
31
+ * @return string
32
+
33
+ */
34
+
35
+ public function compileInsert(Builder $query, array $values)
36
+
37
+ {
38
+
39
+ // Essentially we will force every insert to be treated as a batch insert which
40
+
41
+ // simply makes creating the SQL easier for us since we can utilize the same
42
+
43
+ // basic routine regardless of an amount of records given to us to insert.
44
+
45
+ $table = $this->wrapTable($query->from);
46
+
47
+
48
+
49
+ if (! is_array(reset($values))) {
50
+
51
+ $values = [$values];
52
+
53
+ }
54
+
55
+
56
+
57
+ $columns = $this->columnize(array_keys(reset($values)));
58
+
59
+
60
+
61
+ // We need to build a list of parameter place-holders of values that are bound
62
+
63
+ // to the query. Each insert should have the exact same amount of parameter
64
+
65
+ // bindings so we will loop through the record and parameterize them all.
66
+
67
+ $parameters = [];
68
+
69
+
70
+
71
+ foreach ($values as $record) {
72
+
73
+ $parameters[] = '('.$this->parameterize($record).')';
74
+
75
+ }
76
+
77
+
78
+
79
+ $parameters = implode(', ', $parameters);
80
+
81
+ //ここ!
82
+
83
+ return "insert into $table ($columns) values $parameters";
84
+
85
+ }
86
+
87
+
88
+
89
+ ```