Skip to content

Latest commit

 

History

History
203 lines (150 loc) · 4.11 KB

README.md

File metadata and controls

203 lines (150 loc) · 4.11 KB

Bareq

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Laravel Redis visits counter for Eloquent models

Note: Tested with Laravel 5.5 .

Install

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"

Usage

Increments :

Normal increment

visits($post)->increment();

Increment number of times

visits($post)->increment(10);

Set IP expiration time in seconds

visits($post)->seconds(30)->increment()

Decrement

visits($post)->decrement();

Decrement number of times

visits($post)->decrement(10);

Force increment / decrement

visits($post)->forceIncrement();
visits($post)->forceDecrement();

Top/Low list :

Top 10

visits('App\Post')->top(10)

Lowest 10

visits('App\Post')->low(10)

Get fresh list

visits('App\Post')->fresh()->top(10)

Get top/low of periods

visits('App\Post')->period('month')->top(10)

Counts :

Subject visits

visits($post)->count();

Subject visits period

visits($post)->period('day')->count();

All subjects

visits('App\Post')->count()

All subjects period

visits('App\Post')->period('day')->count()

Countries :

visits($post)->countries()

Referer :

visits($post)->refs()

Resets :

Subject visits

visits($post)->reset();

Subject visits period

visits($post)->period('year')->reset()

Subject recorded ips

visits($post)->reset('ips');
visits($post)->reset('ips', '127.0.0.1');

Reset factory

visits('App\Post')->reset('factory')

Other :

 * visits('App\Post')->reset()
 * visits('App\Post')->reset('lists')
 * visits('App\Post')->period('year')->reset() 

Integration with Eloquent

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();

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

Copy visitsTest.php to your Laravel tests folder and make sure to change the tested model with yours

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Credits

License

The MIT License (MIT). Please see License File for more information.