clqms-be/app/Traits/PatchValidationTrait.php
root 30c4e47304 chore(repo): normalize EOL and harden contact patch flow
- handle contact PATCH failures by checking model save result and returning HTTP 400 with the model error message
- update ContactDetailModel nested updates to enforce active-detail checks and use model update() with explicit failure propagation
- extend contact patch assertions and align test-create variants expectations to status=success for POST responses
- refresh composer lock metadata/dependency constraints and include generated docs/data/test files updated during normalization
- impact: API contract unchanged except clearer 400 error responses on invalid contact detail updates
2026-04-17 05:38:11 +07:00

21 lines
655 B
PHP
Executable File

<?php
namespace App\Traits;
trait PatchValidationTrait {
protected function requirePatchId(mixed $id, string $label = 'ID'): ?int {
if ($id === null || $id === '' || !ctype_digit((string) $id)) {
$this->failValidationErrors("{$label} is required and must be a valid integer.");
return null;
}
return (int) $id;
}
protected function requirePatchPayload(mixed $payload): ?array {
if (!is_array($payload) || empty($payload)) {
$this->failValidationErrors('No data provided for update.');
return null;
}
return $payload;
}
}