百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-user-monitoring

> 后端框架
开源

Laravel 用户监控是一个包,用于在 Laravel 应用中跟踪用户活动,如登录、页面访问和模型交互。它提供了详细的仪表板,

587 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Laravel 用户监控是一个包,用于在 Laravel 应用中跟踪用户活动,如登录、页面访问和模型交互。它提供了详细的仪表板,

Laravel User Monitoring

  • Introduction
  • Installation
  • Usage
    • Configuration
      • Routes Configuration
    • User Configuration
      • Foreign Key Type (UUID, ULID, ID)
    • Visit Monitoring
      • Delete Visit Monitoring Records By Specific Days
      • Turn ON-OFF
      • Views
      • Ajax Requests
      • Visit Monitoring Guest Mode
      • Visit Monitoring Custom Conditions
    • Action Monitoring
      • Views
      • Reverse Proxy Config
      • Action Monitoring Guest Mode
      • Action Monitoring Custom Conditions
    • Authentication Monitoring
      • Views
    • How to use in big projects
  • Contributors
  • Security
  • Changelog
  • License
  • Star History
  • Conclusion
  • Donate

Introduction

Welcome to the world of enhanced user monitoring with the groundbreaking Laravel User Monitoring package! Developed by the brilliant minds at Binafy, this innovative open-source solution is designed to empower Laravel developers and website administrators with invaluable insights into user activities.

Tracking user behavior and interactions is now made effortless, allowing you to better understand your users' engagement, preferences, and pain points. With its seamless integration into Laravel projects, this package opens up a realm of possibilities, enabling you to optimize user experiences, detect bottlenecks, and make data-driven decisions for your platform's success.

Experience real-time monitoring like never before, as you access comprehensive analytics and visualize user interactions with ease. Please don't worry, your users' data is handled securely, respecting privacy while giving you the tools to improve your application's performance and user satisfaction.

Whether you are building a new project or looking to enhance an existing one, "Laravel User Monitoring" is the missing piece to elevate your web applications to new heights. So, why wait? Dive into the world of intelligent user monitoring and witness the transformation of your Laravel-powered application today!

AI Documentation

Installation

  • PHP >= 8.0
  • Laravel >= 9.0

You can install the package with Composer:

bash
composer require binafy/laravel-user-monitoring

Publish

If you want to publish a config file, you can use this command:

bash
php artisan vendor:publish --tag="laravel-user-monitoring-config"

If you want to publish the migrations, you can use this command:

bash
php artisan vendor:publish --tag="laravel-user-monitoring-migrations"

If you want to publish the views, you can use this command:

bash
php artisan vendor:publish --tag="laravel-user-monitoring-views"

If you want to publish the middleware you can use this command:

bash
php artisan vendor:publish --tag="laravel-user-monitoring-middlewares"

If you want to publish the routes you can use this command:

bash
php artisan vendor:publish --tag="laravel-user-monitoring-routes"

For convenience, you can use this command to publish config, migration, and ... files:

bash
php artisan vendor:publish --provider="Binafy\LaravelUserMonitoring\Providers\LaravelUserMonitoringServiceProvider"

After publishing, run the php artisan migrate command.

Usage

The Laravel-User-Monitoring needs to use middleware, traits, etc, and it's not hard, enjoys :)

Configuration

Routes Configuration

If you want to customize the routes, you can publish the route file with this command:

bash
php artisan vendor:publish --tag="laravel-user-monitoring-routes"

After that, you can go to the routes/user-monitoring.php file and customize the routes.

Also, if you want to change the route file name, you can go to the config file and change the file_path:

php
/*
 * Main configuration settings for the package.
 */
'config' => [
    'routes' => [
        /*
         * Path to the route file that handles user monitoring routes.
         */
        'file_path' => 'routes/user-monitoring.php',
    ],
],

User Configuration

You can configure your user with the user-monitoring.php configuration file:

…
  • model: If your user model exists in another place, you can change it to the correct namespace.
  • foreign_key: You can set the user foreign_key name, like customer_id.
  • table: You can write your users table name if it is not `users.
  • guards: The guards are used to authenticate.
  • foreign_key_type: The foreign key type (uuid-ulid-id).
  • display_attribute: The special attribute of the user that you want to show in views.

Foreign Key Type (UUID, ULID, ID)

If you are using uuid or ulid, you can change foreign_key_type to your correct foreign key type:

php
'user' => [
    ...

    /*
     * Specify the type of foreign key being used (e.g., 'id', 'uuid', 'ulid').
     * For non-standard IDs, make sure to add the relevant traits to your models.
     */
    'foreign_key_type' => 'id', // Options: uuid, ulid, id
],

NOTE: You must write uuid or ulid or id.

Visit Monitoring

When you want to monitor all views of your application, you must follow below:

  1. Publish the Migrations

  2. Use VisitMonitoringMiddleware in Kernel.php. You can go to the App/Http folder and open the Kernel.php file and add VisitMonitoringMiddleware into your middleware, for example:

php
use Binafy\LaravelUserMonitoring\Middlewares\VisitMonitoringMiddleware;

// Laravel 11.x or less
protected $middlewareGroups = [
    'web' => [
        ...
        VisitMonitoringMiddleware::class,
    ],

    'api' => [...],
];

// Laravel 12.x
->withMiddleware(function (Middleware $middleware): void {
  $middleware->appendToGroup('web', [VisitMonitoringMiddleware::class]);
})

After, you can see all pages monitoring :)

If you want to disable monitoring for specific pages, you can go to user-monitoring.php that exists in the config folder and add pages into the visit_monitoring key:

php
'visit_monitoring' => [
    /*
     * List of pages that should be excluded from visit monitoring.
     * Add route names or URL paths to this array if you want to exclude certain pages.
     */
    'except_pages' => [
        'user-monitoring/visits-monitoring',
        'user-monitoring/actions-monitoring',
        'user-monitoring/authentications-monitoring',
    ],
],

Delete Visit Monitoring Records By Specific Days

You may delete records by specific days, Laravel-User-Monitoring also supports this .

First, you need to go to the user-monitoring config file and highlight the days that you want to delete:

php
'visit_monitoring' => [
    ...

    /*
     * Set the number of days after which visit records should be automatically deleted.
     * Set to 0 to disable automatic deletion.
     *
     * To enable automatic deletion, configure Laravel's task scheduling as outlined here:
     * https://laravel.com/docs/scheduling
     */
    'delete_days' => 0,
],

After, you need to use Task Scheduling to fire-related command, so go to app/Console/Kernel.php and do like this:

php
command(RemoveVisitMonitoringRecordsCommand::class)->hourly();
    }
}

You can change hourly to minute or second. For more information, you can read Schedule Frequency Options.

Turn ON-OFF

Maybe you want to turn off visit monitoring for some or always; you can use the configuration to turn it off:

php
'visit_monitoring' => [
    ...

    /*
     * Enable or disable the visit monitoring feature.
     * Set false to disable tracking of user visits.
     */
    'turn_on' => true,
    
    ...
]

Visit Monitoring Views

The Laravel-User-Monitoring also has amazing views that you can use very easily, just need to go to the /user-monitoring/visits-monitoring URL, and enjoy:

Ajax Requests

Maybe you may disable record visits for Ajax requests. You can use config to disable it:

php
'visit_monitoring' => [
    ...

    /*
     * Enable or disable monitoring for AJAX requests.
     * Set to false if you do not wish to track AJAX-based page loads.
     */
    'ajax_requests' => true,

    ...
],

When set to false, Ajax requests will not be recorded.

Visit Monitoring Guest Mode

Determines whether to track and store visits for users who are not authenticated (guests). When set to true, the package will also monitor guest user activity. When set to false, only authenticated user visits will be recorded.

php
/*
 * Configuration settings for visit monitoring.
 */
'visit_monitoring' => [
    ...

    /*
     * Determines whether to store `visits` even when the user is not logged in.
     */
    'guest_mode' => true,
],

Visit Monitoring Custom Conditions

The Laravel User Monitoring package allows you to define custom conditions for visit monitoring. Conditions give you full control over when a visit should be logged.

How It Works

  • Conditions are checked before a visit is stored.
  • If any condition returns false, the visit will be skipped.
  • You can define conditions as closures or as class-based rules.
php
'visit_monitoring' => [
    'conditions' => [
        // Class-based condition (must implement MonitoringCondition interface)
        \App\Monitoring\YourCustomCondition::class,

        // Closure-based condition (receives the Request and authenticated User)
        function (Illuminate\Http\Request $request) {
            $user = $request->user();

            return $user && $user->isAdmin();
        },
    ],
],

Action Monitoring

If you want to monitor your model actions, you can use the Actionable trait in your model:

php
 [
    ...
    
    /*
     * Enable or disable monitoring of specific actions (e.g., store, update, delete).
     * Set to true to monitor actions or false to disable.
     */
    'on_store'      => true,
    'on_update'     => true,
    'on_destroy'    => true,
    'on_read'       => true,
    'on_restore'    => false,
    'on_replicate'  => false,
],

Action Monitoring Views

Laravel-User-Monitoring also has amazing views that you can use very easily, just need to go to the /user-monitoring/actions-monitoring URL, and enjoy:

Action Monitoring Reverse Proxy Config

If you are using Reverse Proxy (Nginx or Cloudflare), you can use config to get real IP from a specific header like X-Real-IP or X-Forwarded-For:

php
'action_monitoring' => [
    ...

    /*
     * If your application is behind a reverse proxy (e.g., Nginx or Cloudflare),
     * enable this setting to fetch the real client IP from the proxy headers.
     */
    'use_reverse_proxy_ip' => false,

    /*
     * The header used by reverse proxies to forward the real client IP.
     * Common values are 'X-Forwarded-For' or 'X-Real-IP'.
     */
    'real_ip_header' => 'X-Forwarded-For',
],

Action Monitoring Guest Mode

Determines whether to track and store actions for users who are not authenticated (guests). When set to true, the package will also monitor guest user activity. When set to false, only authenticated user visits will

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPbinafylaravellaravel-frameworklaravel-library

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架