i’m validating request with required and optional fields. When the request does not contain the optional field, it’s skipped and not returned in the validated() function, how can i get the optional field with empty string value in the returned array?
input is [‘field_1’ => ‘test’]
$validator = Validator::make($request->all(), [
‘field_1’ => [‘required’],
‘field_2’ => [‘string’]
]);
dd($validator->validated());
current output is [‘field_1’ => ‘test’]
desire output [‘field_1’ => ‘test’, ‘field_2’ => ‘’]