Skip to content

Commit a724a0a

Browse files
authored
Merge pull request #29 from sasokovacic/add-support-for-insert-ignore
Add support for insert ignore
2 parents a46e0ac + 90e27ff commit a724a0a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/LaravelBatch.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function update(Model $table, array $values, string $index = null, bool $
8585
* @param array $columns
8686
* @param array $values
8787
* @param int $batchSize
88+
* @param bool $insertIgnore
8889
* @return bool|mixed
8990
* @throws \Throwable
9091
* @updatedBy Ibrahim Sakr <[email protected]>
@@ -125,7 +126,7 @@ public function update(Model $table, array $values, string $index = null, bool $
125126
* ];
126127
* $batchSize = 500; // insert 500 (default), 100 minimum rows in one query
127128
*/
128-
public function insert(Model $table, array $columns, array $values, int $batchSize = 500)
129+
public function insert(Model $table, array $columns, array $values, int $batchSize = 500, bool $insertIgnore = false)
129130
{
130131
// no need for the old validation since we now use type hint that supports from php 7.0
131132
// but I kept this one
@@ -160,7 +161,9 @@ public function insert(Model $table, array $columns, array $values, int $batchSi
160161

161162
$valueString = implode(', ', $valueArray);
162163

163-
$query[] = "INSERT INTO `" . $this->getFullTableName($table) . "` (" . implode(',', $columns) . ") VALUES $valueString;";
164+
$ignoreStmt = $insertIgnore ? ' IGNORE ' : '';
165+
166+
$query[] = "INSERT ".$ignoreStmt." INTO `" . $this->getFullTableName($table) . "` (" . implode(',', $columns) . ") VALUES $valueString;";
164167
}
165168

166169
if (count($query)) {

0 commit comments

Comments
 (0)