定制 panchodp/laravel-page-monitor 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

panchodp/laravel-page-monitor

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

panchodp/laravel-page-monitor 适用场景与选型建议

panchodp/laravel-page-monitor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「analytics」 「monitor」 「laravel」 「pages」 「visits」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 panchodp/laravel-page-monitor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 panchodp/laravel-page-monitor 我们能提供哪些服务?
定制开发 / 二次开发

基于 panchodp/laravel-page-monitor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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