Skip to content

Cannot update data collection casts that are null by default. #1053

Open
@oddvalue

Description

@oddvalue

✏️ Describe the bug
Cannot update data collections that are null by default.

↪️ To Reproduce

it('can update a model where the cast is initially null', function () {
    $model = new DummyModelWithCasts();
    $model->setRawAttributes(['data_collection' => null]);
    $model->save();
    assertDatabaseHas(DummyModelWithCasts::class, [
        'data_collection' => null,
    ]);

    $model->update([
        'data_collection' => \Illuminate\Support\Collection::make([new SimpleData('Test')]),
    ]);

    assertDatabaseHas(DummyModelWithCasts::class, [
        'data_collection' => json_encode([['string' => 'Test']]),
    ]);
});

✅ Expected behavior
Should be able to update from null

🖥️ Versions

Laravel: 12.x
Laravel Data: 1.17.0
PHP: 8.3

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