Q: How to customise the Carbon class to calculate age based on months instead years in laravel I am using the Carbon class to calculate the age 
but I would like to customize it so that it can calculate age based on months like 20 months.
here my model
use Carbon\Carbon;
public function getAgeAttribute()
    {
        return Carbon::parse($this->attributes['created_at'])->age;
    }

Any help will be welcomed

A: Carbon has the diffInMonths method which returns the difference between 2 dates in months.
You need to calculate the difference from created_at date up to now.
Here is the code:
public function getAgeAttribute()
{
    $now = Carbon::now();
    return Carbon::parse($this->attributes['created_at'])->diffInMonths($now);
}

