Hello friend, I will learn with you how to use barryvdh/laravel-debugbar in laravel 8. In this post i will explain you with the example of debug package. some of step you need to follow for using this package. Let’s start one by one.
Step 1:
We need to install laravel on our machine.
// I already have laravel installer globally install laravel new laravelApi // here laravelApi is my root directory
Step 2:
Now we need to install barryvdh/laravel-debugbar package, Check the below command.
composer require barryvdh/laravel-debugbar --dev
Note:
Laravel uses Package Auto-Discovery, so doesn’t require you to manually add the ServiceProvider.
If any how laravel doesn’t use Auto-Discovery packages you to add below code. You need go open the config/app.php file and add the service providers.
// ServiceProvider Barryvdh\Debugbar\ServiceProvider::class, //Facade 'Debugbar' => Barryvdh\Debugbar\Facade::class,
After this we need to configure our debugbar package, now we below command to publish.
// run this command in the terminal php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
Step 4
set APP_DEBUG=true into the .env file.
Basically, APP_DEBUG=true it mean laravel displaying the error on runtime and it will also enable debugbar in other words display debugbar bottom on the page.

if you dont want to show any error on the runtime then you need update APP_DEBUG=false or disable debugbar.
Debugbar with Route.
Now we learn how to use barryvdh/laravel-debugbar package with route file. open your routes/web.php file add the below code. here we use debugbar facade with backward slash help to find automatically thier roots.
Route::get('/', function () { \Debugbar::info("hello debugber"); return view('welcome'); });
Output:

Add more method in the route.
Route::get('/', function () { \Debugbar::info("hello debugber"); \Debugbar::error("hello debugber"); \Debugbar::warning('hello debugber'); \Debugbar::addMessage('hello debugber', 'mylabel'); return view('welcome'); });
output :

here you can easily find the differences each method showing different color.
One more live example for user model binding on the route with try and catch. If we get the error the it will show the error otherwise it will show the total users.
Note:- I already generate 100 user with help of User factory.
<?php use Illuminate\Support\Facades\Route; Route::get('/', function () { try { $users = User::count(); \Debugbar::info($users." users Found"); } catch (Exception $e) { \Debugbar::error($e); } return view('welcome'); });
any how we miss the any syntax or anything to our file then is . check the above Code here we miss the User model namespace or path output look like this.

After adding user model path in web.php file.
<?php use Illuminate\Support\Facades\Route; use App\Models\User; Route::get('/', function () { try { $users = User::count(); \Debugbar::info($users." users Found"); } catch (Exception $e) { \Debugbar::error($e); } return view('welcome'); });

How to install laravel and configure
here is the link the package https://github.com/barryvdh/laravel-debugbar