zappem-laravel
Connect your Laravel application to Zappem, (*1)
Installation
$ composer require zappem/zappem-laravel
Then add the following line to your ServiceProviders array in config/app.php:, (*2)
Zappem\ZappemLaravel\ServiceProvider::class
Configuration
Now you'll need to configure Zappem. You can define your configuration in your env file., (*3)
The env variables are:, (*4)
ZAPPEM_URL=http://localhost:3000
ZAPPEM_PROJECT=123456
ZAPPEM_ENABLE=true
- ZAPPEM_URL - The full URL (including port number) where Zappem is running.
- ZAPPEM_PROJECT - The project ID for this application. You can find this on Zappem.
- ZAPPEM_ENABLE - true/false
Alternatively you can define these values in a configuration file., (*5)
$ php artisan vendor:publish
The configuration file will be located in /config/zappem.php., (*6)
Note: You may need to rebuild the cache when changing config variables in Laravel, (*7)
$ php artisan config:cache
Usage
Your application should report errors to Zappem in the report() function in app/Exceptions/Handler.php., (*8)
Here's an example of how it should look:, (*9)
public function report(Exception $e){
if(Config::get('services.zappem.zappem_enable')) \Zappem::exception($e)->send();
}
Passing through a user
If your application requires users to log in, you can send the currently logged in user to Zappem. This will then display in Zappem when viewing the exception., (*10)
public function report(Exception $e){
if(Config::get('services.zappem.zappem_enable')) \Zappem::exception($e)->user(Auth::user()->id)->send();
}
The user() function currently accepts a string or an integer. You should pass through a unique idenfitier of this user. This could be an ID, Email Address etc., (*11)
Getting back an error code
Whenever you send an exception to Zappem, we'll send you back a short unique numeric code. It may be useful to display this to your users. On Zappem you can search for the code and jump to the exception straight away., (*12)
The error code will be contained in the return of sending the exception to us. Here's an example:, (*13)
$Zappem = \Zappem::exception($e)
->user(Auth::user()->id, Auth::user()->name, Auth::user()->email)
->send();
if($Zappem->success){
return "Sorry, an error occurred. Please contact development quoting this code: ".$Zappem->code;
}