Package Data | |
---|---|
Maintainer Username: | if4lcon |
Maintainer Contact: | bderemail@gmail.com (Bader Almutairi) |
Package Create Date: | 2017-09-13 |
Package Last Update: | 2024-07-07 |
Home Page: | https://awssat.com/opensource |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 03:04:39 |
Package Statistics | |
---|---|
Total Downloads: | 132,475 |
Monthly Downloads: | 1,685 |
Daily Downloads: | 62 |
Total Stars: | 963 |
Total Watchers: | 21 |
Total Forks: | 89 |
Total Open Issues: | 5 |
Laravel Visits is a counter that can be attached to any model to track its visits with useful features like IP-protection and lists caching
Via Composer
composer require awssat/laravel-visits
In Laravel 5.4. you'll manually need to register the awssat\Visits\VisitsServiceProvider::class
service provider in config/app.php
.
To adjust the library, you can publish the config file to your project using:
php artisan vendor:publish --provider="awssat\Visits\VisitsServiceProvider"
bareq
to visits
if you missing your data try to revert prefex value to bareq
laravel-visits
doesn't use the default laravel redis configuration (see issue #5)To prvent your data loss add a new conection on config/database.php
'laravel-visits' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 3, // anything from 1 to 15, except 0 (or what is set in default)
],
and you can define your redis connection name on config/visits.php
'connection' => 'default'
It's simple. Using visits
helper as:
visits($model)->{method}()
Where:
visits($model, 'tag1')->increment()
visits($post)->increment();
visits($post)->increment(10);
visits($post)->decrement();
visits($post)->decrement(10);
visits($post)->seconds(30)->increment()
visits($post)->forceIncrement();
visits($post)->forceDecrement();
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('App\Post')->top(10)
visits('App\Post')->low(10)
visits('App\Post')->fresh()->top(10)
alwaysFresh
from package config.visits('App\Post')->period('month')->top(10)
visits($post)->reset();
visits($post)->period('year')->reset()
visits($post)->reset('ips');
visits($post)->reset('ips', '127.0.0.1');
you also can make your custom period by adding a carbon marco in appserviceprovider:
Carbon::macro('endOf...', function () {
//
});
//clear all visits of the given model and its items
visits('App\Post')->reset()
//clear all cache of the top/lowest list
visits('App\Post')->reset('lists')
//clear visits from all items of the given model in a period
visits('App\Post')->period('year')->reset()
//...?
visits('App\Post')->reset('factory')
You can add a visits
method to your model class:
public function visits()
{
return visits($this);
}
Then you can use it as:
$post = Post::find(1);
$post->visits()->increment();
$post->visits()->count();
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
The MIT License (MIT). Please see License File for more information.