Laravel-debugbar: Disable debugbar on some routes

Created on 9 Aug 2014  路  6Comments  路  Source: barryvdh/laravel-debugbar

Hi,

I'd like to disable the debugbar on some routes. I am developing a REST API and each time, the API attaches the debugbar :) I'd like to disable this for some routes.

Is this possible?
Thanks in advance.

Most helpful comment

I called this within my control, and it worked for me:

app('debugbar')->disable();

All 6 comments

What are you returning from your API? It shouldn't affect json/xml responses at all, only text/html responses.

You can set a filter and just call that on your routes.

Route::filter('nodebugbar', function()
{
    \Debugbar::disable();
});

Route::when('api/*', 'nodebugbar');

Do you still have this problem?

How do you do this in laravel 5 ?

Currently I'm doing

Route::post('api', function (IlluminateHttpRequest $request) {

Debugbar::disable();

if(!$request->has('grant_type')) {
    $request->merge([
        'grant_type' => 'password'
    ]);
}

return Response::json(Authorizer::issueAccessToken());

});

look at #409

I called this within my control, and it worked for me:

app('debugbar')->disable();

I just use a handly middleware in my route group.

https://gist.github.com/besrabasant/dd46023f2e09a9000db6db26099e0ae1

Then Register your Middleware in your AppServiceProvider class.

public function boot()
{
    //
    $this->app['router']->aliasMiddleware('noDebugbar', App\Http\Middleware\NoDebugbar::class);
}

Then, in your web.php

Route::group(['middlware' => 'noDebugbar'], function() {

  Route::get('/', function() {
     return view('view');
  });

});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MRZ2017 picture MRZ2017  路  3Comments

linaspasv picture linaspasv  路  5Comments

innerdev picture innerdev  路  5Comments

truongthaison picture truongthaison  路  4Comments

coderdiaz picture coderdiaz  路  4Comments