dinhdjj / visit
Package to tracking visits of a given model
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- jenssegers/agent: ^2.6
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/pest-plugin-test-time: ^1.1
This package is auto-updated.
Last update: 2023-11-04 20:03:26 UTC
README
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.