C
C
cetrarka2017-01-13 00:17:27
Laravel
cetrarka, 2017-01-13 00:17:27

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

2 answer(s)
E
Eugene Wolf, 2017-01-13
@cetrarka

But how and where to check for conditions

It is clear that the award
For example, a user has written 10 articles
you need to check in the same place where the user saves the written article. In Laravel, among other things, there is an event system.
Where the condition may change at some point in time, for example - I wrote above.
In a separate helper class, as an option. In general, it is approximately 99% dependent on the architecture of the application.

A
Andrzej Wielski, 2017-01-13
@wielski

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 question

Ask a Question

731 491 924 answers to any question