Reputation: 898
I use barryvdh/laravel-debugbar. How can I display debugbar only for certain people?
Upvotes: 14
Views: 10077
Reputation: 4556
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);
}
}
Upvotes: 9
Reputation: 31749
You can check for IP address to toggle it in web.php
.
//Enabling DEBUGBAR in Production Only for developers
if(in_array(Request::ip(), [allowed IPs])) {
config(['app.debug' => true]);
}
Upvotes: 2
Reputation: 15951
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.
Upvotes: 2