PHP code example of error-explorer / laravel-error-reporter
1. Go to this page and download the library: Download error-explorer/laravel-error-reporter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
error-explorer / laravel-error-reporter example snippets
use ErrorExplorer\LaravelErrorReporter\Facades\ErrorReporter;
class YourController extends Controller
{
public function someAction()
{
try {
// Your code here
} catch (\Exception $e) {
// Simple facade call
ErrorReporter::reportError($e, 'production', 500);
throw $e; // Re-throw if needed
}
}
}
use ErrorExplorer\LaravelErrorReporter\ErrorReporter;
class YourController extends Controller
{
public function someAction()
{
try {
// Your code here
} catch (\Exception $e) {
// Static call
ErrorReporter::reportError($e, 'production', 500);
throw $e; // Re-throw if needed
}
}
}
use ErrorExplorer\LaravelErrorReporter\Services\WebhookErrorReporter;
class YourController extends Controller
{
public function __construct(
private WebhookErrorReporter $errorReporter
) {}
public function someAction()
{
try {
// Your code here
} catch (\Exception $e) {
// Using injected service
$this->errorReporter->reportError($e, 'production', 500);
throw $e; // Re-throw if needed
}
}
}
use ErrorExplorer\LaravelErrorReporter\Facades\ErrorReporter;
// Simple report with defaults
ErrorReporter::report($exception);
// Report with context
ErrorReporter::reportWithContext($exception, 'staging', 404);
// Full control
ErrorReporter::reportError($exception, 'production', 500, $request);
use ErrorExplorer\LaravelErrorReporter\Facades\ErrorReporter;
// Report a custom message
ErrorReporter::reportMessage('Payment processing failed for user 123', 'production', 500);
// Report with custom context
ErrorReporter::reportMessage(
'Suspicious login attempt detected',
'production',
401,
null,
'warning',
['user_id' => 123, 'ip' => '192.168.1.100']
);
use ErrorExplorer\LaravelErrorReporter\Facades\ErrorReporter;
// Add breadcrumbs for critical steps that might fail
ErrorReporter::addBreadcrumb('User started checkout process', 'user', 'info', ['cart_items' => 3]);
// Log navigation to track user path to error
ErrorReporter::logNavigation('/cart', '/checkout');
// Log critical user actions that might cause issues
ErrorReporter::logUserAction('Attempting payment', ['product_id' => 456]);
// Log failed HTTP requests
ErrorReporter::logHttpRequest('POST', '/api/payment', 500, ['error' => 'timeout']);
// Log slow/problematic database queries
ErrorReporter::logQuery('SELECT * FROM users WHERE id = ?', 2500, ['user_id' => 123, 'slow_query' => true]);
// When an error occurs, all breadcrumbs provide context
try {
// Some operation that might fail
} catch (\Exception $e) {
ErrorReporter::reportError($e); // Includes all breadcrumbs for context
}
use ErrorExplorer\LaravelErrorReporter\Facades\ErrorReporter;
class CheckoutController extends Controller
{
public function processPayment($userId, $amount)
{
// Track critical step that might fail
ErrorReporter::addBreadcrumb('Payment process initiated', 'payment', 'info', ['user_id' => $userId, 'amount' => $amount]);
try {
// Track critical steps (only potential failure points)
ErrorReporter::addBreadcrumb('Validating user', 'validation');
$user = $this->validateUser($userId);
ErrorReporter::addBreadcrumb('Processing payment', 'payment', 'info', ['amount' => $amount]);
$result = $this->paymentService->charge($user, $amount);
// Success: no need to log, just return
return $result;
} catch (ValidationException $e) {
// Report validation error with context
ErrorReporter::reportMessage('User validation failed', 'production', 400, null, 'error', [
'user_id' => $userId,
'validation_errors' => $e->getErrors()
]);
throw $e;
} catch (PaymentException $e) {
// Report payment error - breadcrumbs are
// routes/web.php
Route::get('/test-error-reporting', function () {
throw new \Exception('Test error for Error Explorer');
});
'providers' => [
// ... other providers
ErrorExplorer\LaravelErrorReporter\ErrorReporterServiceProvider::class,
],
'aliases' => [
// ... other aliases
'ErrorReporter' => ErrorExplorer\LaravelErrorReporter\Facades\ErrorReporter::class,
],
// app/Exceptions/Handler.php
use ErrorExplorer\LaravelErrorReporter\Facades\ErrorReporter;
class Handler extends ExceptionHandler
{
public function report(Throwable $exception)
{
// Report to Error Explorer
if (app()->bound('error-reporter-service')) {
ErrorReporter::reportError($exception);
}
parent::report($exception);
}
}
// config/error-reporter.php
'ignore_exceptions' => [
// Add your custom exceptions here
App\Exceptions\CustomIgnoredException::class,
// Remove default ones you want to track
// \Illuminate\Validation\ValidationException::class, // Now this will be reported
],