maxis/laravel-eloquent-guard
Composer 安装命令:
composer require maxis/laravel-eloquent-guard
包简介
Runtime Eloquent performance monitor
README 文档
README
Eloquent Guard is a lightweight, production-ready runtime performance monitor for Laravel. It detects N+1 queries and slow database operations as they happen, helping you keep your application fast and efficient.
✨ Features
- N+1 Query Detection: Automatically detects repeated queries within a single request.
- Slow Query Monitor: Alerts you when a query exceeds your defined time limit.
- Laravel Pulse Integration: Beautiful custom dashboard card to visualize alerts.
- Smart Backtrace: Pinpoints the exact file and line of code causing the issue (skips vendor files).
- Multi-channel Reporting: Built-in support for Log, Slack, Telegram, and Sentry.
- Zero Configuration: Works out of the box with sensible defaults.
📢 Multi-Channel Reporting
Stay informed where your team already works. All alerts include a Smart Backtrace that points directly to your code, skipping the vendor/ noise.
🚀 Installation
You can install the package via composer:
composer require maxis/laravel-eloquent-guard
Usage
Publish Configuration
Publish the configuration file to customize thresholds, ignored tables, and active reporters:
php artisan vendor:publish --provider="Maxis\EloquentGuard\EloquentGuardServiceProvider" --tag="config"
Configure Environment
Add your webhook URLs or bot tokens to your .env file for instant alerts:
ELOQUENT_GUARD_ENABLED=true ELOQUENT_GUARD_SLACK_WEBHOOK=https://hooks.slack.com... ELOQUENT_GUARD_TELEGRAM_TOKEN=your-bot-token ELOQUENT_GUARD_TELEGRAM_CHAT_ID=your-chat-id
Important
Queue Worker Required: To ensure your application's performance is not affected, reporting (Slack, Telegram, Sentry) is handled via Laravel's queue system. Make sure your queue worker is running (php artisan queue:work) to receive alerts.
⚙️ Configuration
Once published, you can find the settings in config/eloquent-guard.php.
Thresholds & Limits
Customize what constitutes a performance issue for your specific application:
'limits' => [ 'n_plus_one_threshold' => 5, // Alert after 5 identical queries in one request 'query_duration_ms' => 500, // Alert if a single query takes more than 500ms ],
Reporters
Enable or disable notification channels by adding/removing classes from the reporters array:
'reporters' => [ \Maxis\EloquentGuard\Reporters\LogReporter::class, // Standard Laravel Logs \Maxis\EloquentGuard\Reporters\SlackReporter::class, // Slack Webhooks (Queue Worker Required) \Maxis\EloquentGuard\Reporters\TelegramReporter::class, // Telegram Bot API (Queue Worker Required) \Maxis\EloquentGuard\Reporters\SentryReporter::class, // Sentry Issue Tracking (Queue Worker Required) ],
Ignored Tables
Prevent noise from system tables (like sessions or cache):
'except_tables' => ['sessions', 'cache', 'pulse_entries', 'jobs', 'migrations'],
📊 Laravel Pulse Integration
Eloquent Guard comes with a dedicated Laravel Pulse card to visualize N+1 and Slow Query trends directly in your dashboard.
Add the Card to Dashboard
Include the Livewire component in your resources/views/vendor/pulse/dashboard.blade.php:
<x-pulse> <!-- Display Eloquent Guard Alerts --> <livewire:maxis.eloquent-guard cols="4" /> <!-- Existing Pulse cards... --> </x-pulse>
🧪 Testing
The package is fully tested with PHPUnit. If you are developing locally or using Laravel Sail, run the test suite with:
# Using Laravel Sail sail php ./packages/maxis/eloquent-guard/vendor/bin/phpunit -c ./packages/maxis/eloquent-guard/phpunit.xml # Or standard PHPUnit from the package directory ./vendor/bin/phpunit
🤝 Contributing
Contributions make the open-source community amazing!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
Distributed under the MIT License. See LICENSE.md for more information.
maxis/laravel-eloquent-guard 适用场景与选型建议
maxis/laravel-eloquent-guard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 20, 最近一次更新时间为 2026 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「monitoring」 「laravel」 「eloquent」 「pulse」 「n-plus-one」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maxis/laravel-eloquent-guard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maxis/laravel-eloquent-guard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maxis/laravel-eloquent-guard 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
A Symfony bundle for chameleon-system/sanitycheck
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
SoftWax Health Check Bundle for Symfony framework
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-10



