Hi, I have a field wich receive a JSON like this:
{"grid":{"product":1,"color":1,"size":1}}
to validate this I'm using this rule:
'grid' => 'required|array|size:3|exists_grid:' . $company_id
At my custom rule exists_grid I do a validation like this:
$this->requireParameterCount(1, $parameters, 'unique_grid');
$company = Company::find($parameters[0]);
$product = $company->produts()->whereProductId($value['product'])->get();
$color = $company->colors()->whereColorId($value['color'])->get();
$size = $company->sizes()->whereSizeId($value['size'])->get();
if ($product->isEmpty() || $color->isEmpty() || $size->isEmpty()){
return false;
}
return $company->grids()
->whereIdProduct($product->first()->ID)
->whereIdColor($color->first()->ID)
->whereIdSize($size->first()->ID)
->count() == 0;
Well when one of the fields (product, color or size) are not found. it return false, but the message, returned to the user is the grid error message. Is there a way to show a error message like: ":field not found" ?
In other words the method would have to have two types of error message
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community