In this episode, we dive into how to build a simple trending system for your Laravel apps. Imagine you have a list of articles, and you want to display the ones people are engaging with most—but you want the list to naturally change as interest fades or shifts to newer content.
We start by adding a trend_score
to each article with a migration, then update our logic so every time someone views an article, that score goes up. Easy enough! But, if we just keep incrementing the score, the most-viewed articles of all time will always stay at the top, even if no one clicks them anymore.
So, we build a Laravel command that periodically "decays" these scores—reducing them by multiplying with a number less than 1 (like 0.97), which lets older, less-viewed content drop over time. We explore how to schedule this command and talk about how adjusting the decay amount and schedule frequency shapes how fast articles rise and fall in the trending list.
Throughout, you'll see how this pattern works live, and you get some ideas on tweaking the system to fit your needs. By the end, you've got a neat and effective way to keep your trending lists fresh in any Laravel project!