Integrating Telebugs with a Laravel application
Any Laravel application can be integrated with Telebugs using the telebugs/telebugs-laravel package. In this guide, you will learn how to install and configure Telebugs in your Laravel application.
For plain PHP applications and scripts, please refer to the PHP integration guide.
Installation
Add the telebugs/telebugs-laravel
package to your composer.json
:
composer require telebugs/telebugs-laravel
Add the Telebugs API key to your Laravel application's environment file at
.env
:
TELEBUGS_API_KEY="YOUR_API_KEY"
You can ask @TelebugsBot for your API key or find it in your project's dashboard.
Register an error handler
Laravel 11.x+
Register an error handling closure in your application's exception handler
at bootstrap/app.php
:
->withExceptions(function (Exceptions $exceptions) {
$exceptions->reportable(static function (Throwable $e) {
if (!app()->bound('telebugs')) {
return;
}
app('telebugs')->report($e)->wait();
});
})
Laravel 8.x-10.x
Register an error handling closure in your application's exception handler
at app/Exceptions/Handler.php
:
public function register()
{
$this->reportable(function (Throwable $e) {
if (!app()->bound('telebugs')) {
return;
}
app('telebugs')->report($e)->wait();
});
}
Sending a test notification
You can send a test notification to your project by running the following command:
APP_ENV=production php artisan tinker --execute="print_r(app('telebugs')->report(new Exception('Hello, Telebugs!'))->wait());"
If everything is set up correctly, you should receive a test notification in your project.
Configuration
The Telebugs configuration file is located at config/telebugs.php
.
You can customize the configuration options by editing this file.
To start editing, you need to publish the Telebugs configuration file:
php artisan vendor:publish --provider="Telebugs\TelebugsLaravel\TelebugsServiceProvider"
For more information on configuring Telebugs, please refer to the PHP integration guide.
Reporting errors
Reporting unhandled errors
Telebugs will automatically report unhandled errors in your Laravel application.
Reporting handled errors
You can manually report errors by calling the app('telebugs')->report()
method:
try {
// Your code here
} catch (Throwable $e) {
app('telebugs')->report($e)->wait();
}
Altenratively, you can use the Telebugs facade and call the
Telebugs::report()
method:
use Telebugs\TelebugsLaravel\Facades\Telebugs;
try {
// Your code here
} catch (Throwable $e) {
Telebugs::report($e)->wait();
}
For more information on reporting errors, configuration details, and advanced usage, please refer to the PHP integration guide.