Laravel rule validate a field less than or greater than another field

Panjeh
3 min readJun 20, 2019

--

In order to validate a field (string , integer or array) under the rule of being less than or greater than another field, there is a simple solution which has been introduced since Laravel 5.6.

The fields can be : string, numeric or array.

Strings, numerics, arrays, and files are evaluated using the same conventions as the size rule. The two fields must be of the same type.

Before you continue with the rest of this tutorial, I would like to introduce two packages for Laravel that I have recently developed: Laravel Pay Pocket, a modern multi-wallet package, and Laravel Failed Jobs, a UI for the Laravel Failed Jobs Table. I hope they may be of help to you.

https://github.com/HPWebdeveloper/laravel-pay-pocket
https://github.com/HPWebdeveloper/laravel-failed-jobs

The validation rules for the case of “less than” are:

lt:field

The field under validation must be less than the given field.

lte:field

The field under validation must be less than or equal to the given field.

The rules for the case of “greater than” are:

gt:field

The field under validation must be greater than the given field.

gte:field

The field under validation must be greater than or equal to the given field.

Thank you for reading! If you enjoyed this article:

Clap it ! Share it! Follow Me in Medium!

Also I’d like to hear your opinion on this article. If you have any doubt, question or suggestion please leave a comment below.

Have a very wonderful day!

Previous Tips You will Love:

--

--

Panjeh
Panjeh

Written by Panjeh

Posting about Python and Laravel

No responses yet