I have a datetime attribute in my class. When it's save, it needs to be saved as datetime and when it's retrieved I need the date, hour and minutes on their own so that I can populate some fields in form model bound blade template.
What is the correct way to save and retrieve this attribute in the format that I require as explained above?
class User extends Model {
protected $dates = ['start_dt'];
public function setStartDtAttribute($startDt, $startHr, $startMin)
{
$this->attributes['start_dt'] = ;
}
}
{!! Form::text('start_dt', isset($user->start_dt) ? $user->start_dt->format('d-m-Y') : Carbon::now()->format('d-m-Y'), ['class' => 'form-control']) !!}
{!! Form::select('start_hr', [
'00' => '00',
'01' => '01',
'02' => '02',
...
'23' => '23'], isset($user->start_dt) ? $user->start_dt->hour : '00', ['class' => 'form-control']) !!}
{!! Form::select('start_min', [
'00' => '00',
'01' => '01',
'02' => '02',
...
'59' => '59'], isset($user->start_dt) ? $user->start_dt->hour : '00', ['class' => 'form-control']) !!}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire