3

I have a class that inherits the Illuminate\Database\Query\Builder, and make a custom method for insert on duplicate key update.

Is there any way to append a suffix to an insert() call?

I've looked around for a bit, and there isn't much resources on suffixes or prefixes to SQL queries in Laravel's query builder.

If avoidable I'd hope to copy the body of the original insert() method in Query Builder into my custom one, because it's not good practice.

Any help is appreciate. Thank you!

Please note I don't use Eloquent for various reasons, but it's too much to explain in this question and it is out of scope.

Thomas Cheng
  • 695
  • 12
  • 26

1 Answers1

0

I have not been able to find any way to do this in query builder itself (short of "raw", which kind of misses the point). But you may want to look at the "Eloquent" updateOrCreate() method, discussed for example at Laravel 5.1 Create or Update on Duplicate, or the related question at Update Duplicate Data when insert data in laravel

There is also an implementation of a insertOnDuplicateKeyUpdate() function at https://gist.github.com/VadimGut/672da182921f70dfcea972e207e86676, which assembles raw SQL and runs it.

TextGeek
  • 1,196
  • 11
  • 23