PHP code example of drsoft28 / visitor-tracker

1. Go to this page and download the library: Download drsoft28/visitor-tracker 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/ */

    

drsoft28 / visitor-tracker example snippets


return [
    /*
    |--------------------------------------------------------------------------
    | Model
    |--------------------------------------------------------------------------
    |
    | This value is the model used for tracking visitors.
    | By default, it uses the package's built-in model.
    | You can replace it with your own model if needed.
    */
    'model' => \Drsoft28\VisitorTracker\Models\VisitorTracker::class,

    /*
    |--------------------------------------------------------------------------
    | Headers to Track
    |--------------------------------------------------------------------------
    |
    | Specify the headers to store in the `request_info` JSON column.
    | Add or remove headers as needed.
    */
    'headers' => [
        'HTTP_USER_AGENT',
        'HTTP_HOST',
        'SERVER_NAME',
        'SERVER_SOFTWARE',
        'REMOTE_ADDR',
        'HTTPS',
    ],
];

'web' => [
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
    \Drsoft28\VisitorTracker\Middleware\VisitorTrackerMiddleware::class,
],

->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \Drsoft28\VisitorTracker\Middleware\VisitorTrackerMiddleware::class,
    ]);
})

use Drsoft28\VisitorTracker\Models\VisitorTracker;

// Get visitors from the last 5 minutes
$recentVisitors = VisitorTracker::visitorsWithinMinutes(5)->get();

   namespace App\Models;

   use Illuminate\Database\Eloquent\Model;

   class CustomVisitorTracker extends Model
   {
       protected $table = 'visitor_trackers';
       protected $fillable = [
           'user_id', 'host_schema', 'host', 'ip', 'path', 'full_url', 'url',
           'country_name', 'country_code', 'region_name', 'region_code', 'city_name',
           'zip_code', 'iso_code', 'latitude', 'longitude', 'timezone', 'referer',
           'route_name', 'route_params', 'request_info',
       ];
   }
   

   'model' => \App\Models\CustomVisitorTracker::class,
   
bash
   php artisan vendor:publish --provider="Drsoft28\VisitorTracker\VisitorTrackerServiceProvider"
   
bash
   php artisan migrate
   
bash
     php artisan config:clear