Laravel debugbar in production

In this article, we are going to show you how you can use a Laravel debugbar library in your production website. Debug Bar is used mainly for debugging environments but there can be situations where you might face an error in production. But debug bar displays all the queries and models of your Laravel application. So you do not want to show it to all of your live users. It should only be displayed to you, the owner of the website.

What we will do:

  1. Install Laravel
  2. Install Debug bar
  3. Enable for a specific user only

Video tutorial:

Install Laravel Debugbar in production website

Download debug bar library (Github) by running the following command in your terminal:

COMPOSER_MEMORY_LIMIT=-1 composer require barryvdh/laravel-debugbar

This will take a few minutes but once installed, you can refresh your browser. The debug bar will not be displayed because the app is in production, so we have to manually display it. But we also want it to be displayed on all pages, throughout the application.

So we will go to the app > providers > AppServiceProvider.php and update it as per the following code:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use Auth;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if (Auth::check() && Auth::user()->email == "your_email@gmail.com")
        {
            \Debugbar::enable();
        }
        else
        {
            \Debugbar::disable();
        }
    }
}

Make sure to add the backslash before it, otherwise, it will generate an error because Laravel works in namespaces. Enter your email address in the if condition. Now you will start seeing a debug bar in your production but only when you are logged in with the above-provided email address.

Conclusion

So that was all, if you face any problems in following this, kindly do let me know in the comments section below.