Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

The Eloquent getDirty() method does not handle the casted attributes right now #349

Closed
arcanedev-maroc opened this issue Dec 23, 2016 · 5 comments

Comments

@arcanedev-maroc
Copy link

For more details:

@robclancy
Copy link

I love how this keeps coming up because Graham has closed all the issues. To the point it needs a master issue. He closes some saying "Duplicate" pointing to one he has closed for no reason ffs.

@quetzyg
Copy link

quetzyg commented Apr 2, 2017

Standard.

@AkenRoberts
Copy link

It looks like cast checking for isDirty() was added just a few days after @quetzyg commented.

@taylorotwell
Copy link
Member

I think this is now implemented?

@hjbdev
Copy link

hjbdev commented Aug 28, 2020

I'm not sure the current implementation has resolved this issue

In a project I'm currently working on (Laravel 6.2) I've had to implement the following workaround in order for the casting to work in getDirty(), otherwise something I've cast as an array comes through as a string.

'my_field_name' => 'array'

// following method is in a trait implemented by a model
public function getRawDiff()
{
    $changed = $this->getDirty();

   dump($changed['my_field_name']); // dumps a string

    foreach($changed as $key => $value) {
        if ($this->hasCast($key)) {
            $changed[$key] = $this->castAttribute($key, $value);
        }
    }

    dump($changed['my_field_name']); // gives me the array

    //...
}

If I'm reading that PR's implementation correctly, the first dump should return an array?

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

No branches or pull requests

6 participants