Skip to content

Instantly share code, notes, and snippets.

@Lelectrolux
Created July 16, 2025 14:26
Show Gist options
  • Save Lelectrolux/339d601be8d8a57cab3e58dd18276423 to your computer and use it in GitHub Desktop.
Save Lelectrolux/339d601be8d8a57cab3e58dd18276423 to your computer and use it in GitHub Desktop.
Add Laravel exception context
<?php
//
$exceptions->context(function (Throwable $e, array $context) {
try {
if (app()->runningUnitTests()) {
$context['isRunningTest'] ??= true;
}
if (app()->runningInConsole()) {
$context['runningIn'] ??= 'console';
$context['command'] ??= $_SERVER['argv'][1] ?? 'unknown';
} else {
$context['runningIn'] ??= 'web';
$context['command'] ??= request()->method().':'.request()->fullUrl();
}
} catch (Throwable) {
}
return $context;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment