vendredi 25 décembre 2015

How to perform validation when updating a unique field using Http\Request in Laravel

I have a customers table that I use a CustomerRequest to validate the fields, through the use of the rules function. The table has an email field which is required and is unique. This works fine when I create the customer, however when I update the customer info (let's say I got their last name spelled wrong) my request fails because the email address is already in the database.

Here is my CustomerRequest:

public function rules()
{
    return [
        'givenname' => 'required',
        'surname' => 'required',
        'email' => 'required|unique:customers,email',
    ];
}

I would like to reuse the CustomerRequest for all of the customer vaildation, how can I go about doing this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire