개발/Laravel
라라벨 요청 전체에 대한 trim 처리 (미들웨어 사용)
Sengwoolee
2020. 7. 31. 17:22
1. Kernel.php 변경
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\TrimStrings::class,
];
2. TrimStrings Middleware
<?php
namespace Illuminate\Foundation\Http\Middleware;
class TrimStrings extends TransformsRequest
{
/**
* The attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
//
];
/**
* Transform the given value.
*
* @param string $key
* @param mixed $value
* @return mixed
*/
protected function transform($key, $value)
{
if (in_array($key, $this->except, true)) {
return $value;
}
return is_string($value) ? trim($value) : $value;
}
}
반응형