在将最终输出发送到浏览器之前操作最终输出的正确方法是什么? (laravel 5。*)
我创建了门面
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);
}
}
在我使用的控制器动作中
return viewMod("my_view_file", array $view_data);
但是我收到损坏的输出(http响应标头被添加到/ prepen到html)
最有可能\与响应相关的__toString方法行为异常
任何想法? (谢谢!)
答案 0 :(得分:1)
您可以使用以下示例中的AfterMiddleware
来自文档,
<?php
namespace App\Http\Middleware;
use Closure;
class AfterMiddleware
{
public function handle($request, Closure $next)
{
$response = $next($request);
// Perform action
return $response;
}
}