0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Laravel】datetime-localのinputにCarbonでformatを整形した日付データを入れても表示されない場合

Last updated at Posted at 2023-12-21

環境

Laravel 10.22.0

状況

データベースからのdatetime型の日付データをBladeのtype="datetime-local"のinputに表示させたい。

以下のように記述しても表示されない

hoge.blade.php
<input class="form-control" type="datetime-local" value="{{ Carbon::parse($date)->format('Y/m/d H:i') }}">

image.png

解決方法

type="datetime-local"のinputはYYYY-MM-DDThh:mmで受けとることを期待しているため、Carbon::parse($date)->format('Y-m-d\TH:i')という風に記述すればよい

hoge.blade.php
<input class="form-control" type="datetime-local" value="{{ Carbon::parse($date)->format('Y-m-d\TH:i') }}">

image.png

おわり

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?