Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

$model->incrementEach() affects all models in the database table (instead of just $model) #57262

Copy link
Copy link
@SjorsO

Description

@SjorsO
Issue body actions

Laravel Version

12.28.1

PHP Version

8.4

Database Driver & Version

No response

Description

Bad way to end the week: I just found out a bunch of our production data is corrupt because of this:

// affects just the `$model` database record
$model->increment('number');

// affects all records in the database table 😢 
$model->incrementEach([
    'number' => 1,
    'another_number' => 1,
]); 

This has been reported before in #49009, but that issue was closed.

It's easy to assume that $model->increment() behaves the same way as $model->incrementEach(). Unfortunately, that assumption leads to corrupted production data. Maybe we can keep this issue open this time to try and get this fixed?

Steps To Reproduce

Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->unsignedInteger('number')->default(0);
    $table->timestamps();
});


$post1 = Post::create(['number' => 0]);
$post2 = Post::create(['number' => 0]);

$this->assertSame(0, $post1->refresh()->number);
$this->assertSame(0, $post2->refresh()->number);

$post1->incrementEach(['number' => 1]);

$this->assertSame(1, $post1->refresh()->number);
$this->assertSame(0, $post2->refresh()->number); // this fails
matthiasPOE

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.