mercredi 2 mars 2016

Laravel 5.2 Validation Request "not-in" not returning custom message

I am setting up a Request class in Laravel 5.2 to process a form. I have a select menu within the form. The first element in the select menu something like the following:

<select name="unique-id">
    <option value="none">Select one...</option>
    <option value="real">Real</option>
</select>

By default the select menu is on "none" - submitting the form with this option selected should result in error; so, I have the following:

class SomeRequest extends Request
{
    ...

    public function rules()
    {
        return [
            'unique-id' => 'not-in:none', // error is caught
            'required-field' => 'required' // error is caught
        ];
    }

    ...
}

The "not-in" rule is caught by the request handler and returns an error; however, the default error message says, "The selected unique-id is invalid" - obviously not the most human of error messages. So, I created the following:

class SomeRequest extends Request
{
    ...

    public function messages()
    {
        return [
            'unique-id.not-in' => 'Must select a valid XXXX.', // does not return
            'required-field.required' => 'Verifying custom errors.' // returns
        ];
    }

    ...
}

I have tried a few variations, but don't want to cloud anyone's answers with that. So, the above is what is currently failing.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TRChzo
via IFTTT

Aucun commentaire:

Enregistrer un commentaire