Laravel - update is incrementing the ID?

- 1 answer


Hello guys,

I'm making an API using Laravel. In one of my scripts, I make an update on a field, like this :

user::where('uuid', $uuid)->update(['date' => $date]);

I noticed that the primary key increments when doing this. My obvious conclusion is that Eloquent makes a delete - insert in place of a regular MySQL update.

And so the question is, why ?

Thanks ahead.




It's not possible that this line of code will update id your records. Whenever you thing something strange happens in your application (not only in Laravel), you should:

  • analyse what exactly code is running that causes this problem (for example you think the error is in this line but you execute also some other custom function where error might occur)
  • verify if there are no extra framework dependant code launched - in this case events for user model
  • verify if there are no triggers in Database (that will automatically update/insert/delete records)