Use fields other than id, other field that make the record unique: From docs
$flight = App\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99]
);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I'm trying to use updateOrCreate, I'm using the "id" as the field to check and if it needs to update it works fine, if it needs to create it tries to create a new row with the id 0.
Getting a bit lost here, anyone has an idea why this doesn't work?
So you are not using auto incrementing id column?
Have you set $incrementing=false; in your model?
Please or to participate in this conversation.