Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use UPDATE OR INSERT with Laravel 4?

I'm building an application in Laravel 4 and I need to run several queries as UPDATE OR INSERT queries to avoid PK violations on duplicate inserts. I haven't been able to find any way to do this with the query builder in Laravel.

Can I modify the DB class or something similar? Or will I need to just write pure SQL statements?

like image 700
Stromgren Avatar asked Nov 28 '22 08:11

Stromgren


1 Answers

Now we can use User::updateOrCreate()

like image 149
Zero Zhang Avatar answered Dec 06 '22 09:12

Zero Zhang