Skip to main content
Back to packages
885 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

Roles and Permissions in Laravel 13

14 lessons
57 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