There's a great extension to laravel: debugbar. But what if I have an REST API. With like no frontend. How do I profile this type of application?
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)
You can try this Middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\JsonResponse;
class ProfileJsonResponse
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
if (
$response instanceof JsonResponse &&
app()->bound('debugbar') &&
app('debugbar')->isEnabled() &&
is_object($response->getData())
) {
$response->setData($response->getData(true) + [
'_debugbar' => app('debugbar')->getData(),
]);
}
return $response;
}
}
Reference https://github.com/barryvdh/laravel-debugbar/issues/252
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With