Support the ongoing development of Laravel.io →
Input Validation

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

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

geshner geshner Joined 27 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.