Laravel: validate an integer field that needs to be greater than another

The question was asked in 2015 so most of the answers are also outdated now.

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 than
  • gte – greater than equal to
  • lt – less than
  • lte – less than equal to

So 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'
]; 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)