Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] incrementEach and decrementEach on a model instance should only update the same record in database #52419

Closed
wants to merge 3 commits into from

Conversation

ebbbang
Copy link

@ebbbang ebbbang commented Aug 7, 2024

incrementEach() and decrementEach() on a model instance will only update the same record in the database.

$user = User::where('shop_id', 1)->first();
$user->decrementEach(['counter' => 1, 'balance' => 100]);
// counter and balance of $user will be decremented.
// All other records will not change.

Please note that the expected behavior of Illuminate\Database\Eloquent\Model, Illuminate\Database\Query\Builder, and Illuminate\Database\Eloquent\Builder is unchanged.

// Decrements all record's counter and balance
User::decrementEach(['counter' => 1, 'balance' => 100]);
DB::table('users')->decrementEach(['counter' => 1, 'balance' => 100]);

// Decrements only user with shop_id = 1
User::where('shop_id', 1)->decrementEach(['counter' => 1, 'balance' => 100]);
DB::table('users')->where('shop_id', 1)->decrementEach(['counter' => 1, 'balance' => 100]);

Related: #49009, #45577 and #48595.

@ebbbang ebbbang changed the title incrementEach and decrementEach on a model instance should only update the same record in database [11.x] incrementEach and decrementEach on a model instance should only update the same record in database Aug 7, 2024
@taylorotwell
Copy link
Member

I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework.

Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants