I want to calculate the average age of users using their birth dates. I have a Model class called Member
, including a function to get the age of the user.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Member extends Model {
public static function averageAge() {
//What to do here
}
public function age() {
$birthDate = Carbon::parse($this->birthDate);
return $birthDate->diffInYears(Carbon::now());
}
}