laravolt / semantic-form

[READ ONLY] Semantic-UI form helper
https://laravolt.dev
MIT License
52 stars 10 forks source link

selectDate() error when used in Model Mutator #1

Closed adhatama closed 8 years ago

adhatama commented 8 years ago

I have

{!! SemanticForm::selectDate('tanggal_lahir')->label('Tanggal lahir')->defaultValue(\Carbon\Carbon::create(1970, 1, 1)) !!}

The tanggal_lahir field is used in my Model Mutator $dates

protected $dates = ['tanggal_lahir'];

When the tanggal_lahir is saved into that Model, it shows error Carbon: Data missing.

InvalidArgumentException in Carbon.php line 425:
Data missing

in Carbon.php line 425
at Carbon::createFromFormat('Y-m-d H:i:s', '2010-1-1') in Model.php line 3015
at Model->asDateTime('2010-1-1') in Model.php line 2971
at Model->fromDateTime('2010-1-1') in Model.php line 2926
at Model->setAttribute('tanggal_lahir', '2010-1-1') in Model.php line 446
at Model->fill(array('nama' => 'oaskdosk', 'nomor_identitas' => '123123', 'agama' => 'ISLAM', 'pendidikan' => 'TIDAK_SEKOLAH', 'pekerjaan' => 'PNS', 'telepon' => '', 'alamat' => '', 'status_pernikahan' => 'MENIKAH', 'nama_pasangan' => '', 'nama_ayah' => '', 'nama_ibu' => '', 'tanggal_lahir' => '2010-1-1')) in Model.php line 280
at Model->__construct(array('nama' => 'oaskdosk', 'nomor_identitas' => '123123', 'agama' => 'ISLAM', 'pendidikan' => 'TIDAK_SEKOLAH', 'pekerjaan' => 'PNS', 'telepon' => '', 'alamat' => '', 'status_pernikahan' => 'MENIKAH', 'nama_pasangan' => '', 'nama_ayah' => '', 'nama_ibu' => '', 'tanggal_lahir' => '2010-1-1')) in Model.php line 500
at Model->newInstance(array('nama' => 'oaskdosk', 'nomor_identitas' => '123123', 'agama' => 'ISLAM', 'pendidikan' => 'TIDAK_SEKOLAH', 'pekerjaan' => 'PNS', 'telepon' => '', 'alamat' => '', 'status_pernikahan' => 'MENIKAH', 'nama_pasangan' => '', 'nama_ayah' => '', 'nama_ibu' => '', 'tanggal_lahir' => '2010-1-1')) in BaseRepository.php line 390
at BaseRepository->create(array('nama' => 'oaskdosk', 'nomor_identitas' => '123123', 'agama' => 'ISLAM', 'pendidikan' => 'TIDAK_SEKOLAH', 'pekerjaan' => 'PNS', 'telepon' => '', 'alamat' => '', 'status_pernikahan' => 'MENIKAH', 'nama_pasangan' => '', 'nama_ayah' => '', 'nama_ibu' => '', 'tanggal_lahir' => '2010-1-1')) in SesiPengkajian.php line 47

I think it is because Model $dates expect 'Y-m-d H:i:s' format from the tanggal_lahir to be converted by Carbon, but tanggal_lahir just have 'Y-m-d' format that composed from the SelectDateMiddleware.

Is it a bug or i am missing something?

Peixer commented 8 years ago

@adhatama you tried to use SemanticForm::selectDateTime('tanggal_lahir')?

uyab commented 8 years ago

@adhatama this problem caused by Laravel and already fixed in https://github.com/laravel/framework/pull/12355