Date Picker Populate Edit View I have the date picker working on the create view and it enters the date. But when I try to retrieve it from the database on the edit view, it doesn't show.
Controller
public function edit($id)
{
$ultreya = Ultreya::find($id);
return view('registrar.ultreya.edit',compact('ultreya'));
}
Edit View
<input type="date" class="form-control @error('date') is-invalid @enderror" name="date" value="{{date('d-m-Y H:i:s',strtotime($ultreya->date))}}">
@error('date')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
database schema
Schema::create('ultreyas', function (Blueprint $table) {
$table->id();
$table->date('date');
$table->string('church');
$table->timestamp('starttime');
$table->string('churchaddress');
$table->mediumText('notes')->nullable();
$table->timestamps();
});
First, it's Date not DateTime, right? why are you using H:i:s?
If you want to set the date value use Y-m-d format.
And it's better to convert date to Carbon object.
To do that, add your column name to $dates array in your model.
class Ultreya extends Model {
protected $dates = ['date'];
}
Then you can use Carbon format method.
<input type="date" value="{{ $ultreya->date->format('Y-m-d') }}" />
Please sign in or create an account to participate in this conversation.