PHP code example of masoudi / laravel-visitors

1. Go to this page and download the library: Download masoudi/laravel-visitors 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/ */

    

masoudi / laravel-visitors example snippets


use Masoudi\Laravel\Visitors\Contracts\Visitable;
use Masoudi\Laravel\Visitors\Traits\InteractsWithVisitors;

class Article extends Model implements Visitable
{
    use InteractsWithVisitors;
}

$totalVisits = visitors()->count();

// Get ip unique count 
$totalUniqueVisits = visitors()->uniqueCount();

$articlesVisitors = Article::visitors()->get();

$article = Article::find(1);
$visitors = $article->visitors()->get();

$article = Article::find(1);

# visit model
$article->visit();

class PostController extends Controller {

    function index(Request $request){
    
        $request->visit();
        
        // Another codes ...
    }
}

// routes/web.php
Route::middleware("visitor")->get("/support", "PageController@support");

Route::middleware("visitor")->group(function (){
        Route::get("posts/{slug}", "PostController@index");
        Route::get("articles/{slug}", "ArticleController@index");
});

$visiCount = visitors()->authId(auth()->id())->count();

$startTime = Carbon::now()->startOfMonth()->toDateTime();
$endTime  = Carbon::now()->toDateTime();

$visiCount = visitors()->range($startTime, $endTime)->count();

use Masoudi\Laravel\Visitors\Contracts\VisitorPlatform;

$visiCount = visitors()->platform(VisitorPlatform::ANDROID)->count();

use Masoudi\Laravel\Visitors\Contracts\VisitorBrowser;

$visiCount = visitors()->browser(VisitorBrowser::CHROME)->count();

$visiCount = visitors()->ipStarts('127.0')->count();

$visiCount = visitors()->ipEnds('0.1')->count();

$visiCount = visitors()->referrers('https://google.com', 'https://facebook.com')->count();

$visiCount = visitors()->paths('/support', '/articles/any-slug')->count();
bash
php artisan vendor:publish --tag=masoudi-laravel-visitors
bash
php artisan migrate