Home > Mobile >  Laravel 8 upsert doesn't work as expected
Laravel 8 upsert doesn't work as expected

Time:01-15

I'm trying use upsert as explained here (enter image description here

The table definition: data table definition

EDIT 1: About the columns types, price and unit_price are int but I tried float because in the CartItem I have they configured in $casts variable to cast them to "Money" type (saving them as cents). I tried with int values but I got the same result.

CodePudding user response:

Laravel upserts do a single query containing all the rows are made while using upsert which includes on duplicate key update in MySQL and on conflict ... do update set in Postgres. This command instructs database to update record if it already exists. You need to pass cart_id to MySQL tries do INSERT before get errors on duplicate.

https://laravelproject.com/laravel-upsert/

  •  Tags:  
  • Related