1. Go to this page and download the library: Download dinhdjj/visit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dinhdjj / visit example snippets
// 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,
];
class Post extends Model
{
use \Dinhdjj\Visit\Traits\Visitable;
}
$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
class User extends Model
{
use \Dinhdjj\Visit\Traits\Visitor;
}
$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