'sometimes|nullable|image', 'birth_date' => 'sometimes|nullable|date', 'document_number' => ['sometimes', 'nullable', 'string', 'max:20', Cpf::rule()], 'gender' => 'sometimes|nullable|string|in:no_preference,male,female,other', 'email' => 'sometimes|nullable|email', 'phone' => 'sometimes|nullable|string|max:20', 'postal_code' => 'sometimes|nullable|string|max:10', 'street' => 'sometimes|nullable|string|max:255', 'address_number' => 'sometimes|nullable|string|max:20', 'neighborhood' => 'sometimes|nullable|string|max:255', 'city_id' => 'sometimes|nullable|integer|exists:cities,id', 'state_id' => 'sometimes|nullable|integer|exists:states,id', 'complement' => 'sometimes|nullable|string|max:255', 'payer_name' => 'sometimes|nullable|string|max:255', 'how_did_you_know_us' => 'sometimes|nullable|string|in:referral,social_media,google,other', 'notes' => 'sometimes|nullable|string', ]; if ($this->isMethod('post')) { $rules['name'] = 'required|string|max:255'; $rules['birth_date'] = 'required|date'; $rules['email'] = 'sometimes|nullable|email|unique:students,email'; $rules['responsible'] = [ 'nullable', 'array', Rule::requiredIf(fn (): bool => $this->studentIsMinor()), ]; $rules['responsible.name'] = 'required_with:responsible|string|max:255'; $rules['responsible.birth_date'] = 'required_with:responsible|date'; $rules['responsible.cpf'] = ['required_with:responsible', 'string', 'max:20', Cpf::rule()]; $rules['responsible.gender'] = 'sometimes|nullable|string|in:no_preference,male,female,other'; $rules['responsible.degree'] = 'required_with:responsible|string|max:255'; $rules['responsible.email'] = 'required_with:responsible|email|max:255'; $rules['responsible.phone'] = 'required_with:responsible|string|max:20'; $rules['responsible.postal_code'] = 'required_with:responsible|string|max:10'; $rules['responsible.street'] = 'required_with:responsible|string|max:255'; $rules['responsible.address_number'] = 'sometimes|nullable|string|max:20'; $rules['responsible.neighborhood'] = 'required_with:responsible|string|max:255'; $rules['responsible.city_id'] = 'required_with:responsible|integer|exists:cities,id'; $rules['responsible.state_id'] = 'required_with:responsible|integer|exists:states,id'; $rules['responsible.complement'] = 'sometimes|nullable|string|max:255'; $rules['responsible.notes'] = 'sometimes|nullable|string'; } else { $rules['name'] = 'sometimes|string|max:255'; } return $rules; } private function studentIsMinor(): bool { $birthDate = $this->input('birth_date'); if (!is_string($birthDate) || $birthDate === '') { return false; } try { return Carbon::parse($birthDate)->age < 18; } catch (Throwable) { return false; } } }