laravel/framework — pull request #5950 by JosephSilber (2014-10-02 16:28:33+00:00)
Title: Add sanitization to form requests

There are two points to this:

1. Sanitize the input before validation, so that we don't reject valid data.
2. Access the sanitized data in the controller, so that we don't have to sanitize twice.

---

Here's how you would use this:

The `RequestForm`:

```php
use Illuminate\Foundation\Http\FormRequest;

class UserFormRequest extends FormRequest {

protected function rules()
{
return ['home_phone' => 'length:10'];
}

protected function sanitize(array $input, SomeSanitizer $sanitizer)
{
return $sanitizer->make($input, ['home_phone' => 'numeric'])->sanitize();
}

}
```

The `Controller`:

```php
class UserController {

public function store(UserFormRequest $request)
{
User::create($request->sanitized());

// or...
$user = new User;
$user->home_phone = $request->sanitized('home_phone');
$user->save();
}

}
```