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.
Each achievement check class extends an abstract
AchievementCheck class and implements a gained() method which returns
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.
Hi @davidrushton, Do you maybe have a code sample for the Achievement class? Thank you!
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us