Support the ongoing development of Laravel.io →
Requests Database Validation
Last updated 2 years ago.
0

In rules() method of your Form Request class you'll have to iterate through events array and set a validator for each element:

public function rules()
{
	$rules = [ 
		//your other rules go here
	];
	$events = $this->input( 'events' );

	if ( !empty( $events ) )
	{
		foreach ( $events as $key => $event ) // add individual rules to each image
		{
			$rules[ sprintf( 'events.%d', $key ) ] = 'min:2';
		}
	}
	return $rules;
}

Alternatively, you could redefine validator() method of the same class and use each() to set rules for each event. I haven't used this particular method, but it should work:

public function validator()
{
	$validator = $this->getValidatorInstance($factory);

	$validator->each('events', 'min:2');
	
	return $validator;
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Nertskull nertskull Joined 3 Apr 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.

© 2024 Laravel.io - All rights reserved.