Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gedeon98's avatar

Displaying old date value in blade

Hello, I am trying to display the date field's old input in my edit form. However, it doesn't display anything. I tried this:

 <input type="date" class="form-control" id="date_of_birth" name="date_of_birth"
           value="{{$user->date_of_birth}}" required>

Thanks in advance!

0 likes
7 replies
Sergiu17's avatar

wrap $user->date_of_birth in old function

value="{{ old($user->date_of_birth) }}"
1 like
gedeon98's avatar

Hello @sergiu17, thank you for responding. I have gotten this error when I tried ur solution:

array_key_exists(): The first argument should be either a string or an integer 

Sergiu17's avatar

@gedeon98 sorry

value="{{ old('date_of_birth') }}"

use just the name of the field

1 like
gedeon98's avatar

@sergiu17 I'm sorry I have not asked my question properly, I am passing an instance of a user to the edit form, and I want to display the existing 'date_of_birth' in the form. I believe the old() method is to conserve inputs when there's a validation error? (I am very new to laravel, so I really appreciate your help).

Sergiu17's avatar
Sergiu17
Best Answer
Level 60

@gedeon98 understood, it doesn't display anything because of the format I guess, you could check this by doing

dd($user->date_of_birth)

if you get back something like 2010-11-11 00:00 - then the problem is in format,

https://jsbin.com/weqarihiwu/4/edit?html,output

in your model ( if you didn't do yet ) you could cast date_of_birth to date

class User {

  protected $casts = [
    'date_of_birth ' => 'datetime:Y-m-d',
  ];
}

// in the view
value="{{ $user->date_of_birth }}"

hope this will work,

I believe the old() method is to conserve inputs when there's a validation error?

yes, you are right

1 like
gedeon98's avatar

@sergiu17 thank you for your guidance, the problem is indeed with the format, I'll do research on how to change it

Please or to participate in this conversation.