Jeremy Belolo
Jeremy Belolo

Reputation: 4539

Laravel - update is incrementing the ID?

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.

Upvotes: 5

Views: 570

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

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)

Upvotes: 1

Related Questions