Reputation: 3022
I'm trying to return a date here is my json format from return Model
{
"date_of_inquiry": "2020-01-01",
"date_of_validity": "2021-01-01",
}
But when I'm returning it to edit.blade in <input type="date" name="date_of_inquiry" value="{{ $client_detail->date_of_inquiry }}" class="form-control" required>
it doesnt display,
what am I missing ?
I'm using laravel 5.6
here is my controller
$quotation = Quotation::find($id);
return view('quotation.edit')
->with('details',$quotation);
Upvotes: 1
Views: 1799
Reputation: 58
Yes, it will probably be enough to change the date format to ISO, like 2012-08-22:
<input name="datedepart" type="date"
value="<?php echo date('Y-m-d',strtotime($data["congestart"])) ?>"/>
Yes, it will probably be enough to change the date format to ISO, like 2012-08-22:
<input name="datedepart" type="date"
value="<?php echo date('Y-m-d',strtotime($data["congestart"])) ?>"/>
If your server expects some other format, you will have to convert it using Javascript (ISO is the standard used in HTML5 specification, so the value of the input field will always be ISO, no matter how Chrome displays it).
update, clarification:
Date field can only contain a valid date. When you try to set it it to some random garbage, then the value becomes empty. When the value is empty - Chrome displays the placeholder. The only valid format for dates in HTML5 is ISO: 2012-03-04. Just try and see:
<input value='2004-02-12' type='date'>
Upvotes: 2
Reputation: 3339
Have you set the date_of_inquiry
as date type in the Eloquent model? (https://laravel.com/docs/5.6/eloquent-mutators#date-mutators)
Then you might want to use {{ $client_detail->date_of_inquiry->format('Y-m-d') }}
(->format...) instead.
You can also just use a @php(dd($client_detail->date_of_inquiry)))
in your .blade.php file to see what is actually in your variable. I doubt that this is the string from your json dump.
You could also could write @php(dd(get_defined_vars())))
in your .blade.php file to output all defined variables and check what was passed to your view.
Upvotes: 1