I have two fields that are optional only if both aren\'t present:
$rules = [
\'initial_page\' => \'required_with:end_page|integer|min:1|digits_between:
the question was asked in 2015 so most of the answers are also outdated now in 2019
i want to give answer which uses features provided by laravel team which is included in it's new version,
so as stated by @Sarpadoruk as of laravel 5.6 laravel added features in validation like
gt,gte,lt and lte which means:
gt - greater thangte - greater than equal tolt - less thanlte - less than equal toso using gt you can check that your end_page should be greater than your initial_page and your task becomes very easy now:
$rules = [
'initial_page' => 'required_with:end_page|integer|min:1|digits_between: 1,5',
'end_page' => 'required_with:initial_page|integer|gt:initial_page|digits_between:1,5'
];