I am validating input by name using Laravel 5.6. I am using the exists rule to determine that the name matches the input and that basic
is equal to 1, like below:
public function rules()
{
$this->sanitizeSpecials($this->all());
return [
'special1' => ['string', 'nullable', 'exists:specials,name,basic,1'],
];
}
Before this validates, I run the name through a sanitizer that transforms it to the case format the name is stored as in the database.
public function sanitizeSpecials($input)
{
if ($input['special1']) {
$input['special1'] = ucwords(str_replace("_", " ", $input['special1']));
}
$this->replace($input);
}
The sanitation function is correct (ex: top_fade
becomes Top Fade
) and specials with no spaces in the name validate correctly, but whenever there is a special with a space in the name like the example Top Fade
, validation fails even though I can verify that the input value matches the value in the database. Why would it be failing like this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire