I have problem when I want to validate parameter values from the array I am pulling from the request:
$content = json_decode($request->getContent(), true);
$name = $content['name'];
$address = $content['address'];
if (!isset($name) && empty($name)) {
echo "Name must be sent.");
}
if (!isset($address) && empty($address)) {
echo "Address must be sent;
}
Maybe just empty() would be enough but it's not just $var as I want to check if that is not an empty value in the array.
When dump() the content, I get:
array:2 [
"name" => "John"
"address" => "Street 007"
]
From some reason validation enters in if and returns echo message evan if value is present
Aucun commentaire:
Enregistrer un commentaire