Laravel Guardian is an all-in-one package for enhancing the security and performance of Laravel applications.
This package automatically scans your application for security and performance issues, generates reports, and even resolves some issues automatically.
- Checks the permissions of sensitive files and directories (
.env,storage,bootstrap/cache) - Detects insecure file permissions (e.g., 777, 775)
- Scans for dangerous files like
phpinfo.php,.git,composer.lock - Validates CSRF protection, APP_KEY, and Debug Mode settings
- Option to automatically remove unsafe files with artisan commands
- Analyzes slow database queries from logs
- Detects large or inefficient Blade views (e.g., excessive loops or includes)
- Recommends enabling caching where appropriate
- Checks for the usage of
eager loadingin models - Provides an automatic optimization command:
php artisan guardian:optimize
- Monitors Laravel logs for new errors and sends alerts (via Telegram, Email, etc.)
- Saves logs in
storage/logs/guardian.log - Sends alerts about detected issues in real-time
- Supports sending alerts via Telegram and Email
- Can be run continuously with
guardian:watchcommand to monitor logs and notify in real-time
Install the package via Composer:
composer require srdev93/laravel-guardianTo publish the configuration file:
php artisan vendor:publish --tag=guardian-configOnce installed, the configuration file will be available at:
config/guardian.php
Example config:
return [
'check_security' => true,
'check_performance' => true,
'auto_fix' => false,
'telegram_bot_token' => env('GUARDIAN_TELEGRAM_BOT_TOKEN', null),
'telegram_chat_id' => env('GUARDIAN_TELEGRAM_CHAT_ID', null),
];You can enable or disable different modules based on your needs (e.g., security, performance).
| Command | Description |
|---|---|
php artisan guardian:scan-security |
Scan for security and performance issues in the application. |
php artisan guardian:optimize |
Automatically optimize the application by clearing caches, optimizing routes, views, and configs. |
php artisan guardian:report |
Generate a report of security and performance status in either JSON or HTML format. |
php artisan guardian:watch |
Continuously monitor Laravel logs for new errors and send notifications. |
After running the guardian:report command, the generated report will show results similar to this:
Guardian Report
========================
✅ Secure: No issues found.
⚠️ Performance: 3 potential slow queries detected.
In HTML format, it will look like this:
<h1>Guardian Report</h1>
<h2>Security</h2>
<ul>
<li>No issues found.</li>
</ul>
<h2>Performance</h2>
<ul>
<li>3 slow queries detected (>200ms)</li>
</ul>- Web dashboard to view security and performance reports
- Integration with Reverb for live monitoring and real-time alerts
- Support for email notifications
- Periodic report generation (daily, weekly)
We welcome contributions! If you have ideas for enhancing Laravel Guardian, feel free to submit a Pull Request or open an Issue.
This package is open-sourced software licensed under the MIT license.
Developed with ❤️ by SrDev93