To address the issue you're facing, the problem arises because the old() function is likely retrieving the time value from the database in the H:i:s format, which includes seconds. However, your validation rule expects the format to be H:i, which does not include seconds.
To solve this, you can format the time value to H:i before passing it to the old() function. You can achieve this by using PHP's Carbon library or the date function to format the time correctly.
Here's how you can modify your code:
-
Format the time value before passing it to the
old()function:If you're using the
Carbonlibrary, you can do something like this:use Carbon\Carbon; $slotDuration = $calendar->slot_duration ? Carbon::createFromFormat('H:i:s', $calendar->slot_duration)->format('H:i') : '';If you prefer using PHP's native
datefunction:$slotDuration = $calendar->slot_duration ? date('H:i', strtotime($calendar->slot_duration)) : ''; -
Update the
valueattribute in your input field:<input type="time" name="slot_duration" value="{{ old('slot_duration', $slotDuration) }}" id="slot_duration" class="block mt-1 w-full" >
By formatting the time value to H:i before it is passed to the old() function, you ensure that the validation rule matches the expected format, thus preventing the validation error.