Skip to content

Conversation

@pxpm
Copy link
Contributor

@pxpm pxpm commented Feb 8, 2022

WHY

BEFORE - What was wrong? What was happening before this PR?

As reported in #4163 , a new feature introduced by Laravel laravel/framework#40022 allow developers to setup acessors and mutators using a different syntax. Backpack guessing abilities were broken by this change, as this functions would look similar to relation functions.

AFTER - What is happening after this PR?

You can safely use the new Laravel feature.

HOW

How did you achieve that, in technical terms?

I prepared the grounds for us to move towards requiring return types in the relation functions that developer wants Backpack to guess from. I moved all logic that deals with checking method properties to a single method to reduce the margin of error until we don't make the change I talked before.

Added a check for the function return type, since the new Laravel feature requires the developer to define the return type, we can safely exclude them from beeing relationships.

Also added a check for method visibility as relationships methods are always public.

Still not perfect until we enforce the return types, but is better than yesterday! 👍

Is it a breaking change or non-breaking change?

non-breaking

How can we test the before & after?

Try adding the new Laravel feature in Monster model for example, before it would error. After it would work 👍

// text is a monster field that we want to mutate, not a relationship
protected function text(): Attribute {
        return new Attribute(
            get: fn($value) => ucfirst($value),
        );
    }

@pxpm pxpm added the Bug label Feb 8, 2022
@tabacitu tabacitu changed the title Refactor entity guessing to account for method visibility and return type Add support for single-method Laravel Accessors and Mutators Feb 9, 2022
@tabacitu
Copy link
Member

Purrfect... Thank you @pxpm . I've just changed the method name, that's all.

Merging!

@tabacitu tabacitu merged commit 986abec into v5 Feb 10, 2022
@tabacitu tabacitu deleted the refactor-model-property-check branch February 10, 2022 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants