- Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
Laravel Version
11.37.0
PHP Version
8.3.13
Database Driver & Version
PostgreSQL 17
Description
When providing an array with non-numeric keys to the Model::upsert method, the behavior in 11.36.0 and older was to use the values of the array as the data. After the changes in #53948, the keys of the array are used as the data, and a database error is returned (because there are no such column names, or because the number of keys does not match the number of values provided).
I understand the rationale for #53948, and I think it makes sense to keep that behavior for Model::insert, but the same behavior makes no sense for Model::upsert because the documentation explicitly describes upsert's first argument as an array of records, not a single record, so using the values makes more sense.
Steps To Reproduce
The following code works in 11.36.0, but crashes with a database error in 11.37.0:
(This is using Laravel's default users table to make it as simple as possible and not need to give a migration as part of the example.)
$users = [ 'user-a' => ['name' => 'User A', 'email': 'user-a@example.com', 'password' => Hash::make('qwerty')], 'user-b' => ['name' => 'User B', 'email': 'user-b@example.net', 'password' => Hash::make('asdfgh')], ]; User::upsert($users, ['email'], ['name', 'password']);