John Davidson

php - how can i paste date in default in blade input

0 comments
Message:


i am getting the date in blade form from controller in format like 2020-11-24(y-m-d) and i want to use this in input field value property


 <div class="row">
<div class="col-md-4">
<label>Surf Date <span class="required">*</span></label>
</div>
<div class="col-md-8">
<div class="selectWrap pos-rel">
<input class="form-control" type="date" name="surf_date" id="datepicker"
value="{{ old('surf_date'),$posts->surf_start_date }}" required />
</div>
</div>
</div>

but it does not working, in input field it shows mm/dd/yyyy by default


i have already used other methods like


                {{date_format(date_create($posts->surf_start_date),"m/d/Y")}}
{{date('m/d/yy', strtotime($posts->surf_start_date))}}
{{ \Carbon\Carbon::parse($posts->surf_start_date)->format('m/d/Y')}}

please help me out. thanks in advance



My Answer:
You can use the `old()` helper function in Blade to set the default value of an input field. Here's an example of how you can achieve this:

php



In this example, `$dateFromController` is the variable that contains the date value passed from the controller in the format '2020-11-24'. The `old('date', $dateFromController)` function will check if there is any old input for the 'date' field, and if not, it will use the value from the controller.

Make sure to replace `'date'` with the actual name of the input field in your form.

Rate this post

4 of 5 based on 7877 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us