Skip to content

Replace ReactionCounter & ReactionTotal observers with attribute casting #244

Discussion options

You must be logged in to vote

Solution №3

public function count(): Attribute
{
    return Attribute::make(
        set: fn (int | null $value) => $value ?? self::COUNT_DEFAULT,
    );
}

public function weight(): Attribute
{
    return Attribute::make(
        set: fn (float | null $value) => $value ?? self::WEIGHT_DEFAULT,
    );
}

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@antonkomarev
Comment options

antonkomarev Apr 10, 2023
Maintainer Author

@antonkomarev
Comment options

antonkomarev Apr 10, 2023
Maintainer Author

Answer selected by antonkomarev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant