PHP code example of voidgraphics / laravel-pageview-counter
1. Go to this page and download the library: Download voidgraphics/laravel-pageview-counter 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/ */
voidgraphics / laravel-pageview-counter example snippets
// bootstrap/app.php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use PageviewCounter\Middleware\LogRequest;
return Application::configure(basePath: dirname(__DIR__))
// ...
->withMiddleware(function (Middleware $middleware) {
$middleware->append(LogRequest::class);
})
// ...
->create();
Pageview::daily()->get(); // Returns the number of views grouped by date and path.
/*
Illuminate\Database\Eloquent\Collection {
all: [
PageviewCounter\Models\Pageview {
views: 156,
path: "/",
date: "2024-07-18",
},
PageviewCounter\Models\Pageview {
views: 68,
path: "about",
date: "2024-07-18",
}
PageviewCounter\Models\Pageview {
views: 289,
path: "/",
date: "2024-07-17",
},
PageviewCounter\Models\Pageview {
views: 32,
path: "about",
date: "2024-07-17",
}
],
}
*/