Search code examples
htmllaraveldatelaravel-5.5mutators

I want to set date into my html date field. I have used mutator in Laravel, Now how can I set date in the date field to edit a record?


This is My mutator in my model..

protected $dates = ['closer_date','final_submission_date','start_date'];

This is a field where I want to set the dates in the fields retrieving record from database.

<input class="form-control" type="date" name="start_date" value="{{ $topic->start_date}}" id = "start_date" onkeyup = "Validate(this)" required min=<?php
                                    echo date('Y-m-d');
                                    ?> />

Solution

  • use format() to set the format

    {{ $topic->start_date->format('Y-m-d')}}
    

    in Your code

    <input class="form-control" type="date" name="start_date" value="{{ $topic->start_date->format('Y-m-d)}}" id = "start_date" onkeyup = "Validate(this)" required min=<?php
                                    echo date('Y-m-d');
                                    ?> />
    

    Hope this helps