Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 478
Jeremy Belolo Avatar asked Nov 09 '22 23:11

Jeremy Belolo


1 Answers

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)
like image 188
Marcin Nabiałek Avatar answered Nov 15 '22 11:11

Marcin Nabiałek