dimanche 12 janvier 2020

Laravel validation 2 different values in a single field

I have a form that would has the field that inputs 2 different values in a single field.

First field is made up with select option dropdown. Once you have selected an option from the first field, the value from the first field will print on the input field. Then in the input field you need to add or type it manually another value to make it work. So the output would look like this:

Selected value - Value added manually

So my problem is how do I validate the field if each one of them is either empty.

I have no idea what I'm doing but this is what I've tried so far but it's not working.

'field' => 'required|in:' . implode(",", Model::values()) . '|unique:table'

This should be the expected output:

  • If the field value is Selected value - Value added manually, it is Valid.

  • If the field value is Selected value -, it should validate to input the 2nd value.

  • If the field value is - Value added manually, it should validate to input the 1st value.

I have searched on google but I'm not sure on what keywords should I searched on but my title sums up on what I have searched recently but I haven't found same problem as mine but if there is, please link it down thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire