How to blade date from database null or not

Viewed 23

I have a value in in my database Here table name: Shift and column name: From. I want to give condition in blade that if shift table's From column's value is not null then my data from "From"column will be displayed on date type input field. I used it in above way but it doesn't work

value="@if(!empty($shift->From)) {{$shift->From}} @endif"

But I got mm/dd/yyyy value in display enter image description here

1 Answers

you should use the old helper incase there are validation errors.

The second parameter of the old() helper is the initial or default value

value="{{ old('from', $shift->From) }}"

(the above assumes that your field is called from. Adapt it to suit.

If you need the date formatted in a specific format, for instance to allow it to be used by a date picker, then probably easiest to create an accessor on the Shift model.

Related