下面是一个清理$ request输入的中间件类如何替换正确传递的$ request。部分$ this->替换($ inputs);我不确定它,我不认为这是正确的,有人可以告诉我它是如何做的。是的,消毒功能是错的我确定所以我需要你的帮助
<?php namespace App\Http\Middleware;
use Closure;
class SanitizeRequest {
private $clean = false;
protected function sanitize(Array $inputs) {
if($this->clean) { return $inputs; }
foreach($inputs as $i => $item) {
if(is_string($item) && !str_contains($i, 'file')) {
$inputs[$i] = trim($item);
}
if(is_string($item) && !str_contains($i, 'html')) {
$inputs[$i] = strip_tags($item);
}
}
$this->replace($inputs);
$this->clean = true;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$this->sanitize($request->all());
$response = $next($request);
return $response;
}
}