-
-
Save shojibflamon/f7b5ea244895f7cb15b5add4a2832414 to your computer and use it in GitHub Desktop.
Auto trim all input [Laravel 5]
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 this class in the middleware folder. | |
<?php namespace App\Http\Middleware; | |
use Closure; | |
class BeforeAutoTrimmer { | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$request->merge(array_map('trim', $request->all())); | |
return $next($request); | |
} | |
} | |
// Step 2. Register this middleware in the application's global HTTP middleware stack (app/Http/Kernel.php) | |
protected $middleware = [ | |
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', | |
'Illuminate\Cookie\Middleware\EncryptCookies', | |
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', | |
'Illuminate\Session\Middleware\StartSession', | |
'Illuminate\View\Middleware\ShareErrorsFromSession', | |
'App\Http\Middleware\VerifyCsrfToken', | |
'App\Http\Middleware\BeforeAutoTrimmer' | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment