-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Laravel
-
Not Needed
-
Boevsson has created Issue #2945: updateOrCreate -> createOrFirst doesn't work as expected in laravel-mongodb. This Jira ticket was filed by GromNaN
Issue Text:
- Laravel-mongodb Version: 4.2
- PHP Version: 8.3.4
- Database Driver & Version: mongod 5.0 / 7.0
Description:
Steps to reproduce
1. $id = $request->get('id') ?? null; // in the case id is null
2. Do `Model::updateOrCreate(['_id' => $id], $data);`
Expected behaviour
A new record should be created with the given data and a generated _id.
Actual behaviour
It queries the first record from the collection and updates it.
This works fine when using the package 4.0 because the createOrFirst is not overriden there in the Mongo Builder class