dinhdjj/visit

This package is abandoned and no longer maintained. No replacement package was suggested.

Package to tracking visits of a given model

v1.1.1 2023-04-06 10:33 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation

You can install the package via composer:

composer require dinhdjj/laravel-visit

You can publish and run the migrations with:

php artisan vendor:publish --tag="visit-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="visit-config"

This is the contents of the published config file:

// config for dinhdjj/laravel-visit package
return [

    /**
     * Table name for visit logs
     */
    'table' => 'visits',

    /**
     * The model class name that will be used to store visit logs, must be a subclass of \Dinhdjj\Visit\Models\Visit
     */
    'model' => Dinhdjj\Visit\Models\Visit::class,
];

Usage

Use Visitable trait

The first thing you need to do is, to use Visitable trait.

class Post extends Model
{
    use \Dinhdjj\Visit\Traits\Visitable;
}

After that, you can use below methods to interact with the visit logs:

    $post = Post::first();

    $post->visitLogs() // relation to visit logs

    $post->visitLogs // collection of visit logs

    $builder = $post->visitLog(User::first()) // builder visit with user as visitor

    $builder->byIp(); // prevent duplicate visit by ip
    $builder->byVisitor(); // prevent duplicate visit by visitor

    $builder->interval(60*15) // prevent duplicate visit within 15 minutes, default is 60*15

    $visit = $builder->log(); // create visit to database

Use Visitor trait

The first thing you need to do is, to use Visitor trait.

class User extends Model
{
    use \Dinhdjj\Visit\Traits\Visitor;
}

After that, you can use below methods to interact with the visit logs:

    $user = Post::first();

    $user->visits() // relation to visit logs

    $post->visits // collection of visit logs

    $builder = $post->visit(Post::first()) // builder visit to post

    // ... same as above

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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