Skip to content

updated_at timestamp not updated on delete if soft deletes enabled #19529

@Namoshek

Description

@Namoshek
  • Laravel Version: 5.4.24
  • PHP Version: 7.0.10
  • Database Driver & Version: php_sqlsrv_7_ts_x64 v4.0.8629.2

Description:

When deleting a model that has soft deletes enabled, the correct update time will be written to the database, but the model itself is not updated with the proper timestamp.

Steps To Reproduce:

I found the issue because of a very small test case that compares all attributes of a model:

// Make a test case out of it...
// Model class has created_at, updated_at and deleted_at timestamps
$model = new Model(['foo' => 'bar']);
$model->save();
sleep(2);
$model->delete();
$this->assertDatabaseHas('models', $model->getAttributes());

Result will be something like the following:

Failed asserting that a row in the table [models] matches the attributes {
    "id": 1,
    "foo": "bar"
    "updated_at": "2017-06-08 16:31:08.000",
    "created_at": "2017-06-08 16:31:08.000",
    "deleted_at": "2017-06-08 16:31:10.000"
}.
Found: [
    {
        "id": "1",
        "foo": "bar",
        "created_at": "2017-06-08 16:31:08.000",
        "updated_at": "2017-06-08 16:31:10.000",
        "deleted_at": "2017-06-08 16:31:10.000"
    }
].

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