Building a trending list of content with Laravel is actually pretty easy. In this snippet, we’ll take a look at how to create a list of trending articles over time, gradually decaying less viewed articles and pushing popular articles to the top.
You’ll also be able to adjust the decay levels, and update the frequency of decay to tweak how sensitive your trending content is and how ‘realtime’ it appears.
If you need to log unique views in Laravel, you might reach for a database table to track IP addresses or another unique piece of data. Let's take a look at speeding things up both in performance and complexity by using Redis and the HyperLogLog probabilistic data structure. Once we're done, we'll set up a period command to sync views back to the database for easy ordering, and then create a trait to share functionality between other models.