So I guess you want to build a system a bit like stackoverflow/stackexchange? I think the best would be to work with Events or model observers, depends on your actions which you want to log.
For example fire an event when the user uploads a picture. You could store the events in a database and log the user actions. And than you get badges too the user.
@psychonetic - That system would be a great example. I was thinking that events might be the best route after doing some research. It sounds much simpler after I read your example... Thanks for the feedback!
We did a bit of work on an event based achievement system in Laravel for http://worldwalking.org.
Essentially in our service provider we bind a checker class to each achievement name (corresponding to the name in the achievements database table), e.g.
$this->app->bind('challenge.achievement.healthy_heart', 'Walking\Challenge\Achievements\HealthyHeartAchievement');
Each achievement check class extends an abstract AchievementCheck
class and implements a gained() method which returns true
or false
depending on whether the user should receive the achievement.
Finally we have an event handler that listens for specific achievement-rewarding events and fires a custom queue job that loops through all the achievements the user hasn't already gained, resolves the checker class out of IoC and 'gains' the achievement (pivot table relation) if the checker class returns true.
notflip said:
Hi @davidrushton, Do you maybe have a code sample for the Achievement class? Thank you!
@notflip did you end up implementing this?
@dangelsaurus @notflip @bar2 Don't know whether you already solved your issue, but I've implemented this feature and release it as an open-source package to Laravel. Here is the link: https://github.com/gstt/laravel-achievements
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community