Menu

1 / 2

Laravel integer:strict Validation Rule Explained

DEV Community: laravel·devTalk·about 22 hours ago
#gQd47pZk
#devtolaravel#devto#dev#strict#integer
Reading 0:00
15s threshold

Here is a small surprise in Laravel validation. The integer rule passes the string "10" . For a form that is fine, because browsers send everything as text. For a JSON API it is a quiet contract break: your docs say age is an integer, a client sends "age": "10" , and you accept it. Laravel has a one-word fix, integer:strict . I ran both rules against a table of values on Laravel 13.35.0 so you can see exactly what changes, including a few results I did not expect.

The tip in one line

$request -> validate ([ 'age' => [ 'required' , 'integer:strict' ], ]);

Enter fullscreen mode

Exit fullscreen mode

The Laravel documentation describes the strict parameter as considering the field valid only if its type is integer , so strings with integer values are invalid. It also notes that plain integer does not check the PHP variable type, only that the input is accepted by PHP's FILTER_VALIDATE_INT .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.