mercredi 2 mars 2016

Trim inputs before validation in the middleware - Laravel

I am using laravel 5.1 and I am validating the inputs in a middleware as below,

public function rules()
{
    return [
        'first_name' => 'required|min:2'
    ];
}

Here if the first_name = '    s' validation passes which i not expected, I need to trim the inputs before the validation happens.

I tried like this,

public function rules()
{
    $this->replace(array_map('trim', $this->all()));

    return [
        'first_name' => 'required|min:2'
    ];
}

But I am getting the same result.

I saw something related to laravel 4.x (LINK)

How to get this done?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire