PHP code example of sindaniel / laravel-telegram-error-reporter
1. Go to this page and download the library: Download sindaniel/laravel-telegram-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/ */
sindaniel / laravel-telegram-error-reporter example snippets
->withExceptions(function (Exceptions $exceptions) {
$exceptions->report(function (Throwable $e) {
// Report to Telegram
app(\Sindaniel\LaravelTelegramErrorReporter\TelegramErrorReporter::class)
->report($e, $errorData);
});
});
use Sindaniel\LaravelTelegramErrorReporter\TelegramErrorReporterFacade as TelegramError;
$result = TelegramError::test();
dd($result);
'environments' => ['production'], // Only report in production
'rate_limit_per_minute' => 5, // Maximum 5 errors per minute
'message_template' => "🚨 *Error in {app_name}*\n\n" .
"**Environment:** {environment}\n" .
"**Message:** {message}\n" .
"**File:** {file}:{line}\n" .
"**URL:** {url}\n" .
"**IP:** {ip}\n" .
"**Time:** {timestamp}",
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Sindaniel\LaravelTelegramErrorReporter\TelegramErrorReporterFacade as TelegramError;
class TestTelegramError extends Command
{
protected $signature = 'telegram:test-error';
protected $description = 'Test Telegram error reporting';
public function handle()
{
try {
// Create a test error
throw new \Exception('This is a test error for Telegram');
} catch (\Exception $e) {
$result = TelegramError::report($e, [
'test_context' => 'Test command executed',
'user' => 'System'
]);
if ($result) {
$this->info('✅ Error successfully reported to Telegram');
} else {
$this->error('❌ Error reporting to Telegram failed');
}
}
}
}
bash
php artisan vendor:publish --provider="Sindaniel\LaravelTelegramErrorReporter\TelegramErrorReporterServiceProvider" --tag="config"
bash
php artisan make:command TestTelegramError