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

[9.x] Adds Attribute::with #41014

Merged
merged 4 commits into from
Feb 15, 2022
Merged

[9.x] Adds Attribute::with #41014

merged 4 commits into from
Feb 15, 2022

Conversation

bvtterfly
Copy link
Contributor

  • This PR adds the possibility to create Attribute using static with method to Laravel 9.

Why?

Laravel has a very expressive syntax, but I think the current syntax of Attributes isn't like other parts of laravel. So I made this PR with a cleaner and more readable way to create them, significantly when disabling object caching.

Current approach:


    public function uppercase(): Attribute
    {
        return (new Attribute(
            get: fn ($value) => strtoupper($value),
            set: fn ($value) => strtoupper($value)
        ))->withoutObjectCaching();
    }


New approach:


    public function uppercase(): Attribute
    {
        return Attribute::with(
            get: fn ($value) => strtoupper($value),
            set: fn ($value) => strtoupper($value)
        )->withoutObjectCaching();
    }


@edemots
Copy link
Contributor

edemots commented Feb 15, 2022

Hey! Since it mimics other parts of Laravel behavior for instantiation, why not use make as the method name?

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

3 participants