xtremer360
8 months ago
1184
8
Laravel

Validation Rules for Field Allowable Null and String

Posted 8 months ago by xtremer360

I'm trying to figure out how I need to structure this validation rules array for my started_at field because this is for an update model form. I need to be able to allow null ONLY in a specific case which I'm covering inside of my custom validation rule. So in other words if the field is filled then it needs to be a string and in the proper date format and then ran through the custom rule but I don't want it to fail if its null. I can't put nullable bercause then that would negate the string validation rule.

'started_at' => [
    'string',
    'date_format:Y-m-d H:i:s',
    new EmploymentStartDateCanBeChanged($this->route('referee'))
]

Please sign in or create an account to participate in this conversation.