angularjslaravel-4phpdebugbar

Laravel-Debugbar not catching AJAX call (Angular call)


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


Solution

  • 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