Laravel 5.1 Create or Update on Duplicate

前端 未结 6 945
悲哀的现实
悲哀的现实 2020-12-03 01:29

In Laravel 5.1, for MySQL insert, I want to see if the record already exists and update on duplicate or create new if none exists.

I have already searched SO where t

6条回答
  •  一整个雨季
    2020-12-03 01:44

    To use laravel function updateOrCreate you need auto increment id in your table.

    what they are doing is

    select id from your_table where your_attributes

    after that get auto increment id

    then

    update your_table set your_values where field_id

提交回复
热议问题