vendredi 29 juin 2018

Laravel: Defining rules or schema for a json field/column

I have a column in my database which it's json type: values.
But I need to enforce a schema.

  • It must be an array
  • Every object must have 2 and only 2 properties (required). code_name, and description
  • code_name must be unique inside that JSON array

Does Laravel has some out of the box feature for this? or do I need to manually decode the json on create and on update to validate that rules?

Till now. I only have this validation rules in my Model:

/**
 * The model validation rules.
 *
 * @var array
 */
public static $rules = [
    'values' => 'required|json', // TO BE CHECKED (values validation (json schema) and setter)
];

But that's not enough.

Important: this is not a duplicate question to: Laravel: validate json object



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

Aucun commentaire:

Enregistrer un commentaire