V
V
vitkuz5732021-02-28 13:16:54
Laravel
vitkuz573, 2021-02-28 13:16:54

How to insert a record if it doesn't exist and update if it exists + get its id?

How can I insert a record into a SQL table so that if it exists, it will be updated (or better, ignored), otherwise created + get its id?
I tried insertOrIgnore, updateOrCreate, it doesn't work as it should, namely I can't get the id or I get the id, but the record update doesn't work (SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question