Last active
September 16, 2016 16:17
-
-
Save sharifbdp/9ed33390ec21d4e3e3dbb8ac45f4e5f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step (1) - Create a middleware; which use to handle the Request data. | |
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
class TrimRequestInputData | |
{ | |
/** | |
* Handle incoming request. | |
* Here we trim all request input value. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$trim_if_string = function ($var) { | |
return is_string($var) ? trim($var) : $var; | |
}; | |
$request->merge(array_map($trim_if_string, $request->all())); | |
return $next($request); | |
} | |
} | |
# Step (2) - Register this middleware in the application's global HTTP middleware | |
# Location - app/Http/Kernel.php | |
protected $middleware = [ | |
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, | |
\App\Http\Middleware\TrimRequestInputData::class, // Here I add this Middleware. | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment