Trim inputs before validation in the Requests - Laravel
<p>I am using <strong>laravel 5.1</strong> and I am validating the inputs in a Requests as below,</p>

<pre><code>public function rules()
{
    return [
        'first_name' =&gt; 'required|min:2'
    ];
}
</code></pre>

<p><strong>Here if the first_name = '&nbsp;&nbsp;&nbsp;&nbsp;s' validation passes which i not expected, I need to trim the inputs before the validation happens.</strong></p>

<p>I tried like this,</p>

<pre><code>public function rules()
{
    $this-&gt;replace(array_map('trim', $this-&gt;all()));

    return [
        'first_name' =&gt; 'required|min:2'
    ];
}
</code></pre>

<p>But I am getting the same result.</p>

<p>I saw something related to <strong>laravel 4.x</strong> (<a href="https://stackoverflow.com/questions/22399326/laravel-4-best-practice-to-trim-input-before-validation">LINK</a>)</p>

<p>How to get this done?</p>

<p><strong>NOTE:</strong> I am <strong>not validating in the controller</strong> by creating a validation instance, I am <strong>using  Request to validate the request</strong>.</p>