My dateTime fields are stored in mySQL as a timestamp and the fields are mutated? as below:
public function getDates()
{
/* substitute your list of fields you want to be auto-converted to timestamps here: */
return array('created_at', 'updated_at', 'start', 'end');
}
I can format in my view nicely now using ->format(' ...'); but in my view I need to show the difference between two dateTimes.
Try something like
public function getDurationAttribute()
{
return $this->end->diffForHumans($this->start);
}
Then just access it using :
$model->duration;
Beware of some edge cases (this code will fail if end is null).
Also you can use the Carbon documentation about dates comparaisons and differences:
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community