Is there a way to display the created_at and updated_at timestamps in human readable format if they are used in a pivot table?
Im new to the whole pivot table laravel thing, but right now i am using a pivot table to store user comments on individual posts and each of these have created_at and updated_at timestamps.
If i was just using an ordinary table with a model i would extend my base model which looks like this:
use Carbon\Carbon;
class Base extends Eloquent {
protected function getHumanTimestampAttribute($column)
{
if ($this->attributes[$column])
{
return Carbon::parse($this->attributes[$column])->diffForHumans();
}
return null;
}
public function getHumanCreatedAtAttribute()
{
return $this->getHumanTimestampAttribute("created_at");
}
public function getHumanUpdatedAtAttribute()
{
return $this->getHumanTimestampAttribute("updated_at");
}
}
But as im not using a model for the pivot tables how would i work around this? Is there a way i can get these functions to work with my pivot tables? Would using a model for the pivot table be the easiest/correct way to do this?
EDIT This is what my relation looks like this is placed in my User Model.
/**
* Guide comments
*
* @return mixed
*/
public function guide_comments()
{
return $this->belongsToMany('Guide', 'guides_comment')->withTimestamps();
}