Pass last_audit_date through for model level validation if not a date

This commit is contained in:
Marcus Moore 2024-03-25 13:47:24 -07:00
parent 675717ff82
commit c98b9da612
No known key found for this signature in database

View file

@ -5,6 +5,7 @@ namespace App\Http\Requests;
use App\Models\Asset;
use App\Models\Company;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use Illuminate\Support\Facades\Gate;
class StoreAssetRequest extends ImageUploadRequest
@ -29,9 +30,15 @@ class StoreAssetRequest extends ImageUploadRequest
: $this->company_id;
if ($this->input('last_audit_date')) {
$this->merge([
'last_audit_date' => Carbon::parse($this->input('last_audit_date'))->startOfDay()->format('Y-m-d H:i:s'),
]);
try {
$lastAuditDate = Carbon::parse($this->input('last_audit_date'));
$this->merge([
'last_audit_date' => $lastAuditDate->startOfDay()->format('Y-m-d H:i:s'),
]);
} catch (InvalidFormatException $e) {
// we don't need to do anything here...
}
}
$this->merge([