datetime-local html input #36794
-
db value: 2022-01-01 03:59:00
🚫 ✅ $casts = ['started_at' => `date:Y-m-d\TH:i:s` ]; Im curious what others are doing to handle basic html date input scenarios Casting works but I feel like I'll need it in full ISO 8601 format for an API & match created_at etc Currently using an jet-input vue component and Also casting seems to work with js Date and default doesn't? idk maybe Im wrong: new Date(model.started_at).toLocaleString(); reference laravel/ideas#1940 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
\Carbon\Carbon::serializeUsing(function ($date) {
if (\Request::wantsJson()) {
return $date->toJson();
}
return (string) $date; // Or any ->format() / translated ->isoFormat() or ->calendar() you want
}); Would allow you to change output for view vs. JSON as you like. But when using Vue.js, I would recommend to keep ISO 8601 string and use UTC instead local timezone for the storage as string in your JS variables. When you'll pass those to |
Beta Was this translation helpful? Give feedback.
Would allow you to change output for view vs. JSON as you like.
But when using Vue.js, I would recommend to keep ISO 8601 string and use UTC instead local timezone for the storage as string in your JS variables.
When you'll pass those to
new Date()
or HTML component, the browser should convert it just fine in local timezone.