Something i did was define a method in the base controller and call it from my other controllers. I think it's pretty straightforward.
astroanu said:
Something i did was define a method in the base controller and call it from my other controllers. I think it's pretty straightforward.
Right, it is straightforward. While I try to figure out a way without modify any controllers in "Laravel way".
It is hard to extend Illuminate\Http\Response
.
I try to use the middleware
public function handle($request, Closure $next)
{
$response = $next($request);
if ($response->headers->contains('Content-Type', 'application/json')) {
$result = [
'status'=>'YES',
'data'=>json_decode($response->getOriginalContent()->toJson())
];
$response->setContent($result);
}
return $response;
}
Note sending $response->getOriginalContent()
to array directly may lost nesting objects' data.
It is inefficient for convering json too many times.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community