vendredi 30 septembre 2016

laravel 'unique' validation property not working

In my Laravel project, I have a form that receives as input name, email etc. and submits the values to a store method in my controller. I created a request to validated the submitted input before storing them in the datebase. Here are the the validation rules and custom messages:

public function rules(){
    return [
        'name' => 'required|unique:users|min:8',
        'email' => 'required|email',
    ];
}


public function messages(){
    return [
        'name.required' => 'You must enter name',
        'name.unique' => 'Sorry, that name is already taken',
        'email.required' => 'An  email address is required',
    ];
}

Ajax and every other part of the code (like the ajax, and laravel) works just fine without the unique validation proberty. But when I include the unique validation, the form does not submit but instead when I look at the developer tools I get the following error:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

all_ajax.js:54 Uncaught TypeError: Cannot read property 'name' of undefined

Please what could I be doing wrong?

For the benefit of doubt let me just add the controller method



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire