0

I am working on project which front end is AngularJS & Backend is Laravel4.

And I am using barryvdh's laravel-debugbar package as debugger

My problem is debugbar showing data when first time load page or i refresh page

But is is not catching when i call api throw angular resourse.

I tried AJAX call configuration as posted in documentation but still not working.

In config file:-

/*
     |--------------------------------------------------------------------------
     | Capture Ajax Requests
     |--------------------------------------------------------------------------
     |
     | The Debugbar can capture Ajax requests and display them. If you don't want this (ie. because of errors),
     | you can use this option to disable sending the data through the headers.
     |
     */

    'capture_ajax' => true,

And In My Controller:-

        Debugbar::addMessage('Another message', 'mylabel');
        Debugbar::warning('Watch out..');
        Debugbar::sendDataInHeaders();

-ND

3
  • Show us your configuration. Commented Jul 11, 2014 at 12:29
  • @Kasyx I have updated , Now see this Commented Jul 11, 2014 at 12:32
  • 1
    Have you read this? phpdebugbar.com/docs/ajax-and-stack.html#ajax Commented Jul 11, 2014 at 12:36

2 Answers 2

2

After searching longtime on web i got solution for this problem

Kindly add this code to your app.js

  .factory('httpInterceptor', function($q) {

        var handle_phpdebugbar_response = function(response) {
             if (phpdebugbar && phpdebugbar.ajaxHandler) {

         var headers = response && response.headers && response.headers();
                if (!headers) {
                     return;
                 }

        var headerName = phpdebugbar.ajaxHandler.headerName + '-id';
               var debugBarID = headers[headerName];
               if (debugBarID) {                           
                     phpdebugbar.loadDataSet(debugBarID, ('ajax'));
                 }
             }
       };

            return {
                request: function(config) {

                    return config || $q.when(config);

                },
                response: function(response) {

                    if (response || $q.when(response)) {

                        handle_phpdebugbar_response(response);
                        return response || $q.when(response);
                    }


                },
                responseError: function(response) {

                    handle_phpdebugbar_response(rejection);
                    return $q.reject(response);
                }
            };
        })
     .config(function($httpProvider) {

            $httpProvider.interceptors.push('httpInterceptor');

     })


This one is in angular module ng-phpdebugbar

Sign up to request clarification or add additional context in comments.

1 Comment

I tried using same code and also tried via module with Angular it gives me error "phpdebugbar is not defined". Any Idea?
1

(Laravel5)

Instead of returning your response, send it to a view:

return \View::make('debug', ['data' => $response]);

instead of

return response()->json($response); 

(don't forget to create the view where you echo your data)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.