LoginSignup
0
0

More than 3 years have passed since last update.

Laravelでユーザーの生年月日をちゃんと表示する

Posted at

ユーザーの生年月日をdate型でデータベースに保存するようにします

そのまま表示しようとすると

1998-09-25

みたいな表示になるので

format関数を使って○月○日みたいな表示を可能にさせます

モデルの変更

対象となるモデルに記述(ここではUser.php)

User.php
protected [
  'birthday'
]

## 表示させたいカラムを指定

はいこれだけ、
これでformat関数が使えます


あとは指定すれば

<p>{{ $user->birthday->format(Y年m月d年) }}</p>

こう表示される

1998年09月25日

モデルに設定を記述しないとエラーが出る

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