Laravel Error handling using Larax

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

  • 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
'providers' => [
Escode\Larax\LaraxServiceProvider::class,
  • Publish larax config file
    Run php artisan vendor:publish --tag=larax-config
use 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

'middleware'=>'auth',

You can set your middleware that’s allow to access exceptions pages over api

'ApiMiddleware'=>'AuthLaraxApi',

You can control data will be saved when exception happened

'exception_data'=>[
'ip'=>true,
'url'=>true,
'headers'=>true,
'body'=>true,
],

You can told Larax to detect user and save his id and his guard with exception data

'detect_user'=>false,
/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”

'ignore_headers'=>[
'Authorization','cookie'
],

You can ignore some fields “remove it from body data” from request body or query string such as “password , image , token”

'ignore_inputs'=>[
'image','password','password_confirmation'
],

You can told larax to notify you by send email when exception happened or not.

'enable_email'=>true,

- 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
Larax Exception Index Page
Larax Exception exception data

i'm full stack software engineer and web pentester, i love programing and ethical hacking , interested in developing web applications and databases