Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Remove deprecated dates property #42587

Merged
merged 1 commit into from May 31, 2022
Merged

Conversation

driesvints
Copy link
Member

It's been over two years since the dates property became deprecated and even longer since the introduction of casts. I feel it's time to remove this property so people can solely rely on the model casts for any datetime attributes.

@taylorotwell taylorotwell merged commit 0d7ac95 into master May 31, 2022
@taylorotwell taylorotwell deleted the remove-dates-property branch May 31, 2022 14:05
@ghoshriju33
Copy link

I know this is a good thing. Sorry if I posted in the wrong place, but the dates property is very useful. Without the $dates property, I have to use $casts and also define an accessor to convert the value to a carbon instance. While $casts is the recommended way, it only works with serialized models. To be honest, the $dates property is really a timesaver.

@driesvints
Copy link
Member Author

@ghoshriju33 what do you mean? why do you need to define an accessor?

@nanaya
Copy link
Contributor

Sorry for posting on an old PR, but was this deprecation announced anywhere? I checked upgrade guide and release notes for 7.x and later and none seem to mention it was being deprecated - only it being suddenly removed in 10.x.

@driesvints
Copy link
Member Author

@nanaya
Copy link
Contributor

nanaya commented Feb 16, 2023

@driesvints I mean the announcement for deprecation, the time people are supposed to update their code ahead of time so it'll continue running fine after being removed in 10.x (also avoids adding new deprecated code and reduces task required for upgrading).

@driesvints
Copy link
Member Author

The @deprecation annotation has been in place for some time now.

@nanaya
Copy link
Contributor

Annotation that isn't visible anywhere isn't really useful. It also doesn't help the update guide is only given on removal instead of deprecation (although for this one it's pretty simple).

@decadence
Copy link
Contributor

Agreed with @nanaya. Deprecations should be noted in the next Upgrade Guides: X-thing is deprecated and will be deleted in future releases, use Y-thing instead. Not everybody monitors GitHub Pull Requests and laravel/framework source code. Unless it's hard to maintain.

@tentus
Copy link
Contributor

This change makes the annotation on getDates() a bit misleading: my code depended on that method to get a list of attributes to then apply a user-specified format to, but now that code skips over everything except the created & updated timestamps.

For anyone else looking for a quick-and-ugly hack to get back to the previous behavior, this worked for me as a short term solution until i can remove references to getDates entirely:

    public function getDates()
    {
        return array_keys(
            array_flip(array_filter(parent::getDates())) + array_filter($this->getCasts(), function ($v) {
                return $v == 'datetime';
            })
        );
    }

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

Successfully merging this pull request may close these issues.

None yet

6 participants