From 81d53185230ba37146885a4f03160f199609b176 Mon Sep 17 00:00:00 2001 From: Khatwangadhareddy Date: Sun, 6 Oct 2024 14:59:28 +0530 Subject: [PATCH] fix: ensure Form::date supports Carbon by checking DateTimeInterface Updated the date validation in Form::date to check if the value implements DateTimeInterface instead of just checking for DateTime instances. This allows compatibility with both DateTime and Carbon objects. --- src/FormBuilder.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 7c0dfe5..7bfbaaf 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -431,7 +431,7 @@ public function number($name, $value = null, $options = []) */ public function date($name, $value = null, $options = []) { - if ($value instanceof DateTime) { + if ($value instanceof \DateTimeInterface) { //By changing the type check to DateTimeInterface, you ensure that the form field can accept both DateTime and Carbon instances. $value = $value->format('Y-m-d'); } @@ -467,7 +467,7 @@ public function datetime($name, $value = null, $options = []) */ public function datetimeLocal($name, $value = null, $options = []) { - if ($value instanceof DateTime) { + if ($value instanceof \DateTimeInterface) { $value = $value->format('Y-m-d\TH:i'); } @@ -517,7 +517,7 @@ public function url($name, $value = null, $options = []) */ public function week($name, $value = null, $options = []) { - if ($value instanceof DateTime) { + if ($value instanceof \DateTimeInterface) { $value = $value->format('Y-\WW'); } @@ -1036,7 +1036,7 @@ public function image($url, $name = null, $attributes = []) */ public function month($name, $value = null, $options = []) { - if ($value instanceof DateTime) { + if ($value instanceof \DateTimeInterface) { $value = $value->format('Y-m'); }