1. Go to this page and download the library: Download shetabit/visitor 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/ */
shetabit / visitor example snippets
$request->visitor()->browser(); // firefox
$request->visitor()->visit($post); // create log for post
$request->visitor()->setVisitor($user)->visit($post); // create a log which says $user has visited $post
visitor()->visit(); // create a visit log
// or you can save log like the below
visitor()->visit($model);
// or like the below
$model->createVisitLog();
// you can say which user has visited the given $model
$model->createVisitLog($user);
// or like the below
visitor()->setVisitor($user)->visit($model);
$model->visitLogs()->count();
// by ip
$model->visitLogs()->distinct('ip')->count('ip');
// by user's model
$model->visitLogs()->distinct('visitor_id')->count('visitor_id');
use Shetabit\Visitor\Models\Visit;
Visit::query()->where('route_name', 'posts.show')->count(); // visits of the posts.show route
visitor()->routeName(); // the name of the route of the current request
visitor()->route(); // the route of the current request
$user->visit(); // create a visit log
$user->visit($model); // create a log which says, $user has visited $model
visitor()->onlineVisitors(User::class); // returns collection of online users
User::online()->get(); // another way
visitor()->isOnline($user); // determines if the given user is online
$user->isOnline(); // another way
'geoip' => true,
'geoip' => true,
'resolver' => 'maxmind',
'maxmind' => [
'database' => storage_path('app/geoip/GeoLite2-City.mmdb'), // where you keep the downloaded database
'locales' => ['en'], // the languages of the country, region and city names, by preference
],
use GeoIp2\WebService\Client;
use Shetabit\Visitor\Resolvers\GeoIp\MaxMindResolver;
$this->app->singleton(MaxMindResolver::class, fn () => new MaxMindResolver(new Client($accountId, $licenseKey)));