Answer the question
In order to leave comments, you need to log in
How to implement the "rewards" system on the site?
Hello. I'm using the standard Auth facade. In what direction should we move in order to implement rewards for the user? For example, a user has written 10 articles and is given a medal on the site. I understand that we need a table with awards, a many-to-many relationship, etc. But how and where to check for the fulfillment of conditions and where to implement the reward assignment code itself?
Answer the question
In order to leave comments, you need to log in
But how and where to check for conditions
For example, a user has written 10 articlesyou need to check in the same place where the user saves the written article. In Laravel, among other things, there is an event system.
1. In the app folder, create a Helpers folder, where you place the Awards.php class
2. Each time you add a news / comment / other, call a specific event (news_added, comment_added) in which you pass the user.
3. In the helper, listen to these events (create listeners) in which you will check. If the added news is the tenth one, issue an award (create an instance of the Award model with user_id equal to the user).
4. Create a Middleware that will "listen" to these events by calling the Awards helper.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question