oh, my god. I noticed the mistake after I posted this.
EDIT: still, pls share a better way to do the validation I just described. Thank you!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm getting an error here:
// error
'address' => ['required'],
'educational_attainment' => ['required', Rule::in(array_keys(SeniorCitizen::$educational_attainments))],
'occupation' => ['required'],
'annual_income' => ['required', 'numeric', 'gte:0'],
'other_skills' => ['nullable'],
// member
'name_of_association' => ['nullable'],
'address_of_association' > ['required_with:name_of_association'],
'date_of_membership' => ['required_with:name_of_association'],
'date_elected' => ['nullable'],
'term' => ['required_with:date_elected']
],
[
'date_of_birth.before' => 'The date of birth must more than 60+ years ago today.', // error here
]
);
// my code
$dt = new Carbon();
$before = $dt->subYears(60)->format('Y-m-d');
$validator = Validator::make(
$request->all(),
[
// personal information
'lastname' => ['required'],
'firstname' => ['required'],
'middlename' => ['nullable'],
// picture
'picture' => ['required', 'image'],
// personal information
'date_of_birth' => ['required', 'date', "before_or_equal:{$before}"],
'sex' => ['required', 'in:male,female'],
'place_of_birth' => ['required'],
'civil_status' => ['required', Rule::in(SeniorCitizen::$civil_statuses)],
'address' => ['required'],
'educational_attainment' => ['required', Rule::in(array_keys(SeniorCitizen::$educational_attainments))],
'occupation' => ['required'],
'annual_income' => ['required', 'numeric', 'gte:0'],
'other_skills' => ['nullable'],
// member
'name_of_association' => ['nullable'],
'address_of_association' > ['required_with:name_of_association'],
'date_of_membership' => ['required_with:name_of_association'],
'date_elected' => ['nullable', 'required_with:name_of_association'],
'term' => ['required_with:date_elected']
],
[
'date_of_birth.before' => 'The date of birth must more than 60+ years ago today.',
]
);
I'm trying to make name_of_association to be nullable, but when not empty, address_of_association and date_of_membership will be required. Then, date_elected can be nullable as well either way, but should only be filled when name_of_association is not empty.
The whole validation was working before, until I added those validations under // member comment.
Please or to participate in this conversation.