Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

timgavin's avatar

Add a End Date Automatically

I have a field that is a dateTime called start_at. I'd like to be able to automatically insert a dateTime value into an end_at field that is exactly one hour later than the start_at field.

DateTime::make('Start At')->rules('required'),

Is this possible? If so, how?

0 likes
3 replies
realrandyallen's avatar
Level 44

Another option is a mutator on the model

public function setStartAtAttribute($value)
{
    $this->attributes['start_at'] = $value;
    $this->attributes['end_at'] = Carbon::parse($value)->addHour();
}

Please or to participate in this conversation.