Is there a quick way to modify a SQL query generated by Laravel’s Fluent to have an INSERT IGNORE instead of the usual INSERT?
I’m trying to insert an array with fifty elements. Writing out the entire query manually will bloat up the code and make it more susceptible to human errors.
For the job you need to create a new Grammar that will have the right string in there:
grammar.php (1)
The grammar is a public property of the
DBor in this caseDatabasestored connection. This is not really straight forward, but from the visibility of the properties you should be able to inject your special grammar into the database layer.I also suggest you bring the issue up with the project, they probably have got a better idea how to make that more flexible for cases like these.
(1) This was a former, to the date of the answer reference. If you see this today, you need to adopt to the Laravel version you use, e.g. Grammar.php for 4.0, these classes have moved into
laravel/framework.