-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add INSERT IGNORE support to Query Builder #9612
Comments
Yes but is it supported by mssql, postgresql and sqlite? |
A quick google shows that SQLite supports a somewhat similar construct but for the other DBMS's you would need to either use |
|
Also, you can't chain onto
|
You probably just want to use a raw query here. |
Using raw query is fine for inserting a single row/array. However, as the |
A good soul has published a package that can add this capability to a model: https://github.com/jdavidbakr/replaceable-model |
Here is what worked for me: https://stackoverflow.com/a/45151709/370290 |
Because this very old issue is the # 1 hit on google for insert ignore query builder... what works best for us is firstOrCreate. |
|
@phpguru |
@GrahamCampbell Could we re-open this? Is there anyway we could vote on this feature? Judging from the responses on this issue, this feature would be very useful for many people who use databases that allow insert ignore. |
Found this great Laravel extension that adds support for INSERT & UPDATE (UPSERT) and INSERT IGNORE to the query builder and Eloquent: staudenmeir/laravel-upsert |
Laravel's Query Builder now has <?php
DB::table('users')->insertOrIgnore([
['id' => 1, 'email' => 'taylor@example.com'],
['id' => 2, 'email' => 'dayle@example.com']
]); Read more here: https://laravel.com/docs/5.8/queries#inserts |
@dunhamjared thank you! Exactly what I was looking for. |
It would be very useful to have ability to use IGNORE statement like this
DB::connection('foo')->table('bar')->insert($rows)->ignore();
For additional details check MySQL docs: http://dev.mysql.com/doc/refman/5.6/en/insert.html
The text was updated successfully, but these errors were encountered: