Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show laravel debugbar only to certain people?

I use barryvdh/laravel-debugbar. How can I display debugbar only for certain people?

like image 451
Sizuji Avatar asked Jul 24 '18 04:07

Sizuji


Video Answer


2 Answers

Check the documentation here: https://github.com/barryvdh/laravel-debugbar

If you want to enable/disable debugbar at runtime, use this codes:

\Debugbar::enable();
\Debugbar::disable();

You may do something like this. Create a middleware php artisan make:middleware TestMiddleware, Don't forget to edit app/Http/Kernel.php and add TestMiddleware

protected $middleware = [
        ...
        \App\Http\Middleware\TestMiddleware::class,
        ...
    ];

Then this is your TestMiddleware.php

<?php

namespace App\Http\Middleware;

use Closure;

class TestMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (auth()->user() && in_array(auth()->id(), [1,2,3])) {
            \Debugbar::enable();
        }
        else {
            \Debugbar::disable();
        }

        return $next($request);
    }
}
like image 118
aceraven777 Avatar answered Oct 22 '22 22:10

aceraven777


You can do this in this in Your AppServiceProvider.php

namespace App\Providers;
use Barryvdh\Debugbar\ServiceProvider as Bry;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {


    }
   public function register(){

      if($_SERVER['REMOTE_ADDR'] == 'YourIp'){
         $this->app->register(Bry::class); // or $this->app->register(new  Barryvdh\Debugbar\ServiceProvider()); 
       }

   }

By this way you can register ServiceProvider dynamicaly.

Hope this helps.

like image 21
Romantic Dev Avatar answered Oct 22 '22 22:10

Romantic Dev