samrat415 / mattermost-laravel
Get Laravel Exception alerts on mattermost channels
Fund package maintenance!
samrat415
Requires
- php: ^8.3
- illuminate/contracts: ^10.0||^11.0||^12.0
- illuminate/http: ^10.0 || ^11.0 || ^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
This package is auto-updated.
Last update: 2025-06-16 12:33:00 UTC
README
A Laravel package to send exception alerts directly to Mattermost via incoming webhooks.
Built using Spatie Laravel Package Tools for clean and automatic integration.
🧭 Overview
This package catches exceptions in non-API requests and automatically sends a rich, formatted message to your Mattermost channel with details like:
- App/environment
- Host
- User info
- URL & payload
- Exception message, file, and line
🖼️ Screenshots
Step-by-step setup:
Step | Image |
---|---|
1️⃣ Add incoming webhook | ![]() |
2️⃣ Configure channel & description | ![]() |
3️⃣ Copy the webhook URL | ![]() |
Example Message on Web & Mobile:
Web | Mobile |
---|---|
![]() |
![]() |
📦 Installation
composer require samrat415/mattermost-laravel
⚙️ Setup
1. 🧪 Create Incoming Webhook on Mattermost
Follow the screenshots above or these steps:
- Go to Main Menu > Integrations > Incoming Webhooks
- Click Add Incoming Webhook
- Select the channel and give a name like
Laravel Alerts
- Copy the generated Webhook URL
2. 🔐 Environment Variables
Add the following to your .env
file:
MATTERMOST_WEBHOOK_URL=https://your-mattermost/hooks/your-webhook-url MATTERMOST_ALERT_ENABLED=true MATTERMOST_REDIRECT_BACK=true
Key | Description |
---|---|
MATTERMOST_WEBHOOK_URL |
Your Mattermost webhook URL |
MATTERMOST_ALERT_ENABLED |
Set to false to temporarily disable notifications |
MATTERMOST_REDIRECT_BACK |
Set to false to prevent redirecting back after an error |
3. ⚙️ Publish Config (Optional)
php artisan vendor:publish --tag="mattermost-laravel-config"
This will publish the configuration file to:
config/mattermost-alert.php
✅ Automatic Exception Reporting
This package automatically hooks into Laravel’s exception handling:
- Only for non-API web requests
- Catches exceptions and reports to Mattermost
- Optionally redirects back with flash alert
🧾 Blade Alert Message (Optional UI)
To show the alert message on your front-end after exception handling, add this snippet to your main layout file:
@if (session()->has('alert')) <div class="alert alert m-2 bg bg-{{ session()->get('alert')['type'] }} p-4 text-white rounded alert-dismissible" role="alert"> <h4 class="alert-heading d-flex align-items-center"> <span class="alert-icon rounded-circle" style="border: 2px solid white; padding: 8px; display: inline-flex; align-items: center; justify-content: center;"> @if (session()->get('alert')['type'] === 'success') <i class="bx bx-coffee"></i> @elseif(session()->get('alert')['type'] === 'danger') <i class="bx bx-error"></i> @else <i class="bx bx-show"></i> @endif </span> {{ session()->get('alert')['title'] }} </h4> <hr> <p class="mb-0">{{ session()->get('alert')['message'] }}</p> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div> @endif
🧪 Testing
Throw an exception anywhere in your Laravel web route or controller to test. If everything is configured properly, the error will show up in your Mattermost channel.
🔒 License
MIT © Samrat Thapa