hmdev1/lern
LERN records Laravel exceptions to your database and sends notifications via Monolog channels like email, Slack, Pushover, SMS (Twilio/Plivo), Sentry, and more. Helps capture request/user context for faster debugging across Laravel versions.
Installation:
composer require tylercd100/lern
php artisan vendor:publish --provider="Tylercd100\LERN\LERNServiceProvider"
php artisan migrate
Configure app/Exceptions/Handler.php:
use Tylercd100\LERN\Facades\LERN;
public function report(Throwable $e)
{
if ($this->shouldReport($e) && app()->bound("lern")) {
LERN::handle($e); // Records + Notifies
}
return parent::report($e);
}
First Use Case:
Trigger an exception (e.g., abort(500)) and verify:
vendor_tylercd100_lern_exceptions.Exception Handling Pipeline:
LERN::record($exception) → Stores data in DB.LERN::notify($exception) → Sends alerts via Monolog.LERN::handle($exception) → Combines both.Dynamic Data Collection:
Enable fields in config/lern.php:
'collect' => [
'method' => true, // HTTP method (GET/POST/etc.)
'data' => true, // Request payload
'user_id' => true, // Authenticated user ID
'url' => true, // Request URL
]
Notification Customization:
resources/views/exceptions/default.blade.php.LERN::setLogLevel('emergency'); // Overrides config
LERN::setUser($user); // Sets $user for current request
Handler.php:
if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpException && $e->getStatusCode() >= 500) {
LERN::handle($e);
}
LERN::pushHandler(new \Monolog\Handler\SyslogHandler('udp://logs.example.com'));
Migration Conflicts:
vendor_tylercd100_lern_exceptions exists, reset it or rename the table in config/lern.php before migrating.Notification Delays:
LERN::notify($e) directly to isolate issues.User Data Gaps:
user_id requires authentication. Use middleware to set it:
LERN::setUser(auth()->user());
Deprecated Methods:
LERN::setMessage() if using Blade templates (set 'view' => null in config).$lastException = \Tylercd100\LERN\Models\ExceptionModel::latest()->first();
dd($lastException->toArray());
lern.notify.log_level to debug to capture all events during testing.Custom Models:
Extend ExceptionModel to add fields (e.g., environment, device_info):
class CustomExceptionModel extends \Tylercd100\LERN\Models\ExceptionModel {
protected $fillable = ['environment', 'device'];
}
Update config/lern.php:
'model' => App\Models\CustomExceptionModel::class,
Handler Priorities:
Use LERN::pushHandler() for runtime additions (e.g., staging-only alerts):
if (app()->environment('staging')) {
LERN::pushHandler(new \Monolog\Handler\SlackHandler(env('SLACK_TOKEN'), '#staging-alerts'));
}
Rate Limiting:
Combine with Laravel’s throttle middleware to avoid notification spam:
LERN::notify($e)->throttle(5); // Max 5 notifications/minute
How can I help you explore Laravel packages today?