What is the proper way to manipulate final output before sending it to browser? (laravel 5.*)
I have created facade
namespace App\Facades;
use Illuminate\Support\Facades\Response as ResponseFacade;
use Illuminate\Http\Response as ResponseHttp;
class Response extends ResponseFacade
{
public static function viewMod($view, $data = [], $status = 200, array $headers = [])
{
$output = \Response::view($view, $data, $status, $headers);
return some_manipulating_function($output);
}
}
and in the controller action i use
return viewMod("my_view_file", array $view_data);
but i receive corrupted output (http response headers are added to/ prepended to html)
most probably \Response related __toString method behaves strangely
any ideas? (thanks!)
You can use AfterMiddleware
like below example from docs,
<?php
namespace App\Http\Middleware;
use Closure;
class AfterMiddleware
{
public function handle($request, Closure $next)
{
$response = $next($request);
// Perform action
return $response;
}
}
来源:https://stackoverflow.com/questions/31182355/manipulating-laravel-html-response-just-before-sending-it-to-browser