Laravel validation Form - Don't accept number into double quotes
I have this POST request:
{
"documentType": "1",
"metadata": []
}
And i have this validation rules:
const POST_RULES = [
'documentType' => 'required|int',
'metadata' => 'array',
];
The problem is:
I don't want accept this value of documentType ("1") because it's a string. Users of the application can send a string.
I need to accept only number (1, 2, 3, 4 etc ...) whitout double quotes.
It's possible to create rule for that ?
Thank's in advance,
Solution 1:
In the POST request, send number without quotes
{
"documentType": 1,
"metadata": []
}
You required an INT, not a STRING.
Or, you can accept the "1" and then check if that is a number:
if (is_numeric($request->documentType)) {
// Do other stuff
return true
}