Laravel Redis visits counter for Eloquent models
Note: Tested with Laravel 5.5 .
Via Composer
$ composer require if4lcon/bareq
The package will automatically register itself in Laravel 5.5. In Laravel 5.4. you'll manually need to register the if4lcon\Bareq\BareqServiceProvider::class
service provider in config/app.php
.
You can publish the config file with:
php artisan vendor:publish --provider="if4lcon\Bareq\BareqServiceProvider"
visits($post)->increment();
visits($post)->increment(10);
visits($post)->seconds(30)->increment()
visits($post)->decrement();
visits($post)->decrement(10);
visits($post)->forceIncrement();
visits($post)->forceDecrement();
visits('App\Post')->top(10)
visits('App\Post')->low(10)
visits('App\Post')->fresh()->top(10)
visits('App\Post')->period('month')->top(10)
visits($post)->count();
visits($post)->period('day')->count();
visits('App\Post')->count()
visits('App\Post')->period('day')->count()
visits($post)->countries()
visits($post)->refs()
visits($post)->reset();
visits($post)->period('year')->reset()
visits($post)->reset('ips');
visits($post)->reset('ips', '127.0.0.1');
visits('App\Post')->reset('factory')
* visits('App\Post')->reset()
* visits('App\Post')->reset('lists')
* visits('App\Post')->period('year')->reset()
add visits
method to your model :
public function visits()
{
return visits($this);
}
and you can access it by calling :
$post = Post::find(1);
$post->visits()->increment();
$post->visits()->count();
Please see CHANGELOG for more information on what has changed recently.
Copy visitsTest.php
to your Laravel tests folder and make sure to change the tested model with yours
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
The MIT License (MIT). Please see License File for more information.