vendredi 16 août 2019

Validate value where another column's value for the record is in array of values

Input to be validated is a tree where a subcategory is valid, only if its' parent category has been selected too.

The input values are as follows:

$categories = [1,2,3];

//in database, each subcategory has column "category_id"
$sub_categories = [4,5,6]

Validation

$this->validate([
 "sub_categories.*" => [
  "exists:sub_categories,id",
  //Rule for checking that the category_id for this subcategory
  //exists in the categories array.
 ]
])


Is there such a built in laravel rule or do I need to write the rule myself?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KA4Fau
via IFTTT

Aucun commentaire:

Enregistrer un commentaire