Skip to content

incrementEach and decrementEach dont respect where query when used for eloquent model #48595

@hanicab

Description

@hanicab

Laravel Version

9.52.15

PHP Version

8.1.19

Database Driver & Version

MySQL 8.0.33 for macOS 13.4.1 on arm64 (Homebrew)

Description

incrementEach() and decrementEach() dont respect where condition when used for eloquent model.

$user = User::where('shop_id', 1)->first();
$user->decrementEach(['counter' => 1, 'balance' => 100]);

All users in the table are decremented whatever 'shop_id' they have.

Please note that the problem is only if executed via eloquent model , but works correctly if executed via direct query as below

User::where('shop_id', 1)->decrementEach(['counter' => 1, 'balance' => 100]); // works correctly

Steps To Reproduce

incrementEach() and decrementEach() dont respect where condition when used for eloquent model.

$user = User::where('shop_id', 1)->first();
$user->decrementEach(['counter' => 1, 'balance' => 100]);

All users in the table are decremented whatever 'shop_id' they have.

Please note that the problem is only if executed via eloquent model , but works correctly if executed via direct query as below

User::where('shop_id', 1)->decrementEach(['counter' => 1, 'balance' => 100]); // works correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions