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
Comment options

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