From c98b9da612a701a49119bdc0a1b7ff8dfe928ab8 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 25 Mar 2024 13:47:24 -0700 Subject: [PATCH] Pass last_audit_date through for model level validation if not a date --- app/Http/Requests/StoreAssetRequest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index d87d5bc2fb..918972c6cc 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -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([