Skip to main content
Back to packages
884 GitHub stars

cyrildewit/eloquent-viewable

View on GitHub

Description

This Laravel package allows you to associate views with Eloquent models.

Once installed you can do stuff like this:

// Return total views count
views($post)->count();
 
// Return total views count that have been made since 20 February 2017
views($post)->period(Period::since('2017-02-20'))->count();
 
// Return total views count that have been made between 2014 and 2016
views($post)->period(Period::create('2014', '2016'))->count();
 
// Return total unique views count (based on visitor cookie)
views($post)->unique()->count();
 
// Record a view
views($post)->record();
 
// Record a view with a cooldown
views($post)->cooldown(now()->addHours(2))->record();

Related Content on Laravel Daily

Video

Recent Courses on Laravel Daily

Laravel 13 Eloquent: Expert Level

41 lessons
1 h 34 min

Queues in Laravel 13

18 lessons
1 h 12 min read

How to Build Laravel 13 API From Scratch

30 lessons
1 h 23 min

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.