I'm working on a piece of functionality that simply allows a guest user to perform an action a certain number of times before requiring them to login\create account. In this instance, they can vote on photos in a gallery 5 times before the app asks them to create an account.
My solution is roughly as follows.
- On initial load, set cookie with vote_count=1;
- retrieve and increment vote_count each time a user votes;
- When vote_count=5, redirect user to page asking them to login or sign up. (of course the user can delete their cookies or use another browser etc, but I'm not concerned with that right now).
My problem is where to implement this code.
- Even though I will only call this feature on one route, I feel the controller is the wrong place because it adds quite a bit of code, and if I change the number of times a user can vote, I'm changing code in the controller (maybe that's not a bad thing?)
- I don't believe this should live in a helpers.php file because it's not needed anywhere else in the app.
- I guess I could create it's own class and it could live as a static method, but I feel static methods are best left for functionality in which they will always return the same value and have the same result regardless of where they are called.
To put this into a good question. What is a good OOP way of implementing this that fits in line with Laravel?