jeudi 26 avril 2018

Laravel Validation Integer accepts empty string?

Im creating some small API with which i can create blog posts through postman. Im using laravel 5 and i encoutered a problem.

In the API call, i can specify a user id, so the post is written by someone else than whoever makes the API call right now. My currently logged in user is specified with a token in postman.

So my problem is now, when i create the API call and specify my user_id as empty string "userID": ""

it will throw an error, because i specified the id to be an int like so

'userID' => ['integer']

The error is

"Type error: Argument passed to construct() must be of the type integer or null, string given",

Why does it accept an empty string? How can i validate that correctly?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2JuNhRd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire