承接 panchodp/laravel-page-monitor 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

panchodp/laravel-page-monitor

最新稳定版本:v1.3.0

Composer 安装命令:

composer require panchodp/laravel-page-monitor

包简介

Monitor page visits in your Laravel application. Each visit is stored in the database with information about the user (authenticated or guest), device type, IP address, and timestamp.

README 文档

README

Logo for Laravel Page Monitor

PHP Total Downloads Latest Stable Version License Tests

Laravel Page Monitor

Monitor page visits in your Laravel application. Each visit is stored in the database with information about the user (authenticated or guest), device type, IP address, and timestamp.

Compatibility

Laravel PHP Package
13.x 8.4+ ^1.x
12.x 8.4+ ^1.x
11.x 8.4+ ^1.x

Installation

composer require panchodp/laravel-page-monitor

Publish everything at once

php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider"

Or publish each piece individually:

# Migration
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-migrations"

# Configuration
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-config"

# Views
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-views"

# Assets (CSS/JS)
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-assets"

Then run the migration:

php artisan migrate

This creates the page_visits table with the following columns:

Column Description
id Auto-increment primary key
page Route name or full URL
user_id Authenticated user ID, null for guests
session_id Session identifier
ip_address Visitor IP (supports IPv4 and IPv6)
device_type mobile, tablet, or desktop
user_agent Raw User-Agent string
visited_at Visit timestamp

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-config"

This creates config/laravel_page_monitor.php:

return [
    'enabled'         => env('MONITOR_ENABLED', true),
    'user_model'      => env('PAGE_MONITOR_USER_MODEL', 'App\Models\User'),
    'middleware'      => ['web', 'auth'],
    'track_all'       => env('MONITOR_TRACK_ALL', false),
    'track_guests'    => env('MONITOR_TRACK_GUESTS', true),
    'excluded_routes' => [],
    'pruning' => [
        'retention_days' => env('MONITOR_RETENTION_DAYS', 30),
        'max_records'    => env('MONITOR_MAX_RECORDS', 10000),
    ],
    'per_page' => env('MONITOR_PER_PAGE', 50),
];
  • enabled: Enable or disable the monitor globally. Defaults to true.
  • user_model: The Eloquent model used to associate authenticated visits. Change this if your application uses a custom User model.
  • middleware: Middleware applied to the /page-monitor dashboard route. Defaults to ['web', 'auth'].
  • track_all: When true, all routes in the web middleware group are tracked automatically — no need to add visits-count to each route manually. The /page-monitor dashboard is always excluded. Defaults to false.
  • track_guests: When false, only visits from authenticated users are recorded. Guest visits are silently ignored. Defaults to true.
  • excluded_routes: Route names that should never be tracked. Supports wildcards. Livewire update requests are always excluded automatically regardless of this list. Defaults to [].
  • pruning: Controls automatic cleanup of old records (see Artisan Commands).
  • per_page: Number of records shown per page in the dashboard. Defaults to 50.
// Use a custom user model
'user_model' => 'App\Models\Admin',

// or via .env
PAGE_MONITOR_USER_MODEL=App\Models\Admin

Usage

1. Track pages

Option A — Track all pages automatically

Set track_all to true in the config (or via .env) and every route in the web group is tracked with zero additional setup:

MONITOR_TRACK_ALL=true

Option B — Track specific routes manually

Add the visits-count middleware only to the routes you want to monitor:

// Single route
Route::get('/home', HomeController::class)->middleware('visits-count');

// Route group
Route::middleware('visits-count')->group(function () {
    Route::get('/home', HomeController::class);
    Route::get('/about', AboutController::class);
});

2. View the dashboard

Navigate to /page-monitor to see all recorded visits with page, user, device type, IP address, and timestamp.

The dashboard requires authentication by default (auth middleware). To restrict access further, define the view-page-monitor gate in your AppServiceProvider:

use Illuminate\Support\Facades\Gate;

Gate::define('view-page-monitor', fn ($user) => $user->isAdmin());

You can also replace the middleware entirely via the config:

// config/laravel_page_monitor.php
'middleware' => ['web', 'auth', 'role:admin'],

Facade

You can query visit data anywhere in your application using the Facade:

use Panchodp\LaravelPageMonitor\Facades\LaravelPageMonitor;

// Pages grouped and sorted by most visited first
$ranking = LaravelPageMonitor::ranking();

// Pages grouped and sorted alphabetically A → Z
$byName = LaravelPageMonitor::byNameOrder(desc: false);

// Pages grouped and sorted alphabetically Z → A
$byNameDesc = LaravelPageMonitor::byNameOrder(desc: true);

Each method returns an Illuminate\Database\Eloquent\Collection where each item contains page, visits (total count), and last_visit.

You can also query the PageVisit model directly for full control:

use Panchodp\LaravelPageMonitor\Models\PageVisit;

// All visits for a specific page
PageVisit::where('page', 'home')->get();

// Visits by authenticated users only
PageVisit::whereNotNull('user_id')->with('user')->get();

// Visits from mobile devices today
PageVisit::where('device_type', 'mobile')
    ->whereDate('visited_at', today())
    ->get();

Artisan Commands

Prune old records

php artisan pagemonitor:prune

Deletes records based on the pruning config. Add it to your schedule for automatic cleanup:

// routes/console.php
Schedule::command('pagemonitor:prune')->daily();

You can tune the limits in the config (or disable them with null):

'pruning' => [
    'retention_days' => 30,    // delete visits older than 30 days
    'max_records'    => 10000, // keep at most 10,000 records
],

Reset all visit records

php artisan pagemonitor:reboot-count

Deletes all recorded visits from the database.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固