php - Dingo API add metadata to all responses -
i trying add user-specific metadata every api response using dingo api , thought best way in addmetadata
middleware:
<?php namespace app\http\middleware\api; use closure; use dingo\api\http\request; class addmetadata { public function handle(request $request, closure $next) { $response = $next($request); /* * dingo api response has ability modify metadata responses */ if ($response instanceof \dingo\api\http\response) { $oldmeta = $response->getmeta(); $meta = array_merge($oldmeta, $request->user()->metadata()); $response->setmeta($meta); } return $response; } }
what finding response @ point no longer dingo api response , such, unable add metadata. have tried using dingo\api\http\response::makefromexisting()
method create new response old request, i've tried instantiating new response appears dingo api response processed before getting middleware.
what efficient way of adding user-specific metadata response? don't want adding every api endpoint individually if @ possible.
Comments
Post a Comment