user11124425
user11124425

Reputation: 971

validation and duplicate update() in laravel

In my form Voiture, I want to do a validation system for the fields immatriculation and num_vehicule

Here i an overview:

enter image description here

If I edit the first recording ie the value of the field num_vehicule 000001 per 0000032and that I validate, I have an error message because the value of the field immatriculation already exists.

enter image description here

I don't understand the problem... Do you have an idea please?

'immatriculation' => 'required|string|max:15|min:6|unique:voitures,immatriculation',
'num_vehicule' => 'required|string|max:6|min:6|unique:voitures,num_vehicule',
'fk_modele' => 'required'

Thank you

Upvotes: 0

Views: 147

Answers (1)

Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9693

Use

'immatriculation' => 'string|max:255|unique:voitures,immatriculation,' . $this->voitures->id,

The syntax is

 'input_field' => 'unique:<table name>,<column name for this input field>, <unique id>, <unique id column in table>';

Upvotes: 3

Related Questions