wrap $user->date_of_birth in old function
value="{{ old($user->date_of_birth) }}"
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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!
@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
Please or to participate in this conversation.