2021年1月6日星期三

Laravel validate request filter field with dot (period) in field name

Here is to validate form request in laravel, request contains filter and field name in the filter has period(dot) present.

Sample Request url

...?filter[entity.abc][]='value'

Here entity.abc is actually a string, but laravel considers it to be array of object, when rule is given for 'filter.entity.abc'

filter:[      [entity]: [ {abc:'value'}]        ]    

which is actually

filter:[     [entity.abc]:['value']  ]    

So we need to make regex for second dot, which equivalents to:

public function rules()  {      return [          'filter.entity\.abc' => ['bail', 'sometimes', 'array'],          'filter.entity\.abc' => ['uuid']      ];  }  

Above always retuns true,even when invalid uuid is present

https://stackoverflow.com/questions/65584612/laravel-validate-request-filter-field-with-dot-period-in-field-name January 06, 2021 at 02:32AM

没有评论:

发表评论