laravel擴展包統計頁面訪問次數——awssat/laravel-visits,用于統計在每個頁面的訪問次數,通過判斷IP來實現通過訪問次數的功能。
項目地址:https://github.com/awssat/laravel-visits
安裝命令:
composer require awssat/laravel-visits
安裝成功之后將配置文件發布出來:
php artisan vendor:publish --provider="awssat\Visits\VisitsServiceProvider"
會生成配置文件config/visits.php
為了提高統計的性能,我們需要進行額外的配置
在config/database.php中redis選項增加以下內容:
'laravel-visits' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 3, // anything from 1 to 15, except 0 (or what is set in default)
],
完整的代碼如下:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'laravel-visits' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 3, // anything from 1 to 15, except 0 (or what is set in default)
],
],