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

Award a badge to a user on demand #12

Closed
hosseincode opened this issue Aug 12, 2019 · 1 comment
Closed

Award a badge to a user on demand #12

hosseincode opened this issue Aug 12, 2019 · 1 comment

Comments

@hosseincode
Copy link

I would like to award a specific badge to a user inside my listener that listens to an event. Is there a method similar to givePoint() that i can use for this purpose?

For example assume i have a badge called AvatarUploadedBadge and i want to award it to the authenticated user first time they upload an avatar. Is there a method i can use inside my listener that listens to the AvatarWasUploadedEvent?

@saqueib
Copy link
Member

saqueib commented Aug 12, 2019

Try this in your qualifier method

/**
     * Check is user qualifies for badge
     *
     * @param $user
     * @return bool
     */
    public function qualifier($user)
    {
        return !is_null($user->avatar);
    }

And you can call the syncBadges() method to assign the badge when you upload the avatar.

// upload avatar
$user->avatar = $uploadedAvatarPath;
$user->save();

// in Listener AvatarWasUploadedEvent
$user->syncBadges();

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

No branches or pull requests

2 participants