I have been trying to figure this one out for quite a whiale and have gone through every post from here and Laracast to figure this out but in vein.
I have done this before and it worked but I am not quite sure why it doesn't now.
Basically setting up a rule in your form request should follow the format below:
<?php
class MyFormRequest extends Request{
public function rules(){
return [
'field' => 'required|unique:table_name:field,' . $this->input('field');
];
}
}
This to me should work but according to my experience at the moment doesn't. I have tried to separate the rules by checking the incoming request method and assign rules based on whether the request is an update or create.
Shouldn't what I have suffice for this requirement? What would be the best way of re-using my FormRequest but making sure that I am able to validate uniqueness of as many table fields as I want regardless of their data types because I am sensing that perhaps this is related to the fact that Laravel seems to be doing an aggregate on the field being validated and if it is not an integer for example it will keep on displaying the error message.
Another possible way of solving this is if I implement my own validation method for the fields I am interested to validate. How would I go about doing this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire