When you work on any project , whether it staging or production , and your project must be available all the time, so there should be a way to know what errors are occurring in the project in real time.
- Larax is laravel package help us to log exceptions happened in our laravel applications and notify us with all the data we need to find out the cause of the problem when exception happened such as (data user sent it in body, headers ,user ip , user id and his guard) .
- How to Install Larax
- larax repo in github https://github.com/es-code/larax
- Run “composer require escode/larax”
- Add Larax Service Provider to providers array in “/config/app.php”
'providers' => [
- Publish larax config file
php artisan vendor:publish --tag=larax-config
- Run migrate command
php artisan migrate
- Going to “/app/Exceptions/Handler.php” and make it extends from “Escode\Larax\ExceptionHandler”
class Handler extends ExceptionHandler
- How to configure Larax
- open “/config/larax.php” file
You can set your middleware that’s allow to access exceptions pages on website
You can set your middleware that’s allow to access exceptions pages over api
You can control data will be saved when exception happened
You can told Larax to detect user and save his id and his guard with exception data
/Note: if you enable detect user in exception larax will push StartSession::class and EncryptCookies::class in $middleware Kernel.php to can read cookie and session
//and you should be comment StartSession::class from $middlewareGroups => web
You can ignore some keys “remove it from headers data” from request headers such as “Authorization”
You can ignore some fields “remove it from body data” from request body or query string such as “password , image , token”
You can told larax to notify you by send email when exception happened or not.
- How to use Larax
If you follow installation steps larax now can fetch exception happened in your application.
Open “http://localhost:8000/larax/exceptions" to see the exceptions did happened in your application.
- You can do some filters in your exceptions with date and time range or solved/un-solved or search by user ip or user id
- You can mark exception is solved/un-solved
- You can read your application exceptions data over Api just do “GET” request to “http://localhost:8000/api/larax/exceptions" using user key as bearer token.