| Total Complexity | 3 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class SignupStat extends Model |
||
| 9 | { |
||
| 10 | use HasFactory; |
||
|
|
|||
| 11 | |||
| 12 | protected $guarded = []; |
||
| 13 | |||
| 14 | public static function insertUsersByMonth(): void |
||
| 15 | { |
||
| 16 | $users = User::query() |
||
| 17 | ->whereNotNull('created_at') |
||
| 18 | ->where('created_at', '<>', '0000-00-00 00:00:00') |
||
| 19 | ->selectRaw("DATE_FORMAT(created_at, '%Y-%m-01') as sort_date, DATE_FORMAT(created_at, '%M %Y') as mth, COUNT(id) as num") |
||
| 20 | ->groupBy(['sort_date', 'mth']) |
||
| 21 | ->orderByDesc('sort_date') |
||
| 22 | ->get(); |
||
| 23 | |||
| 24 | foreach ($users as $user) { |
||
| 25 | self::updateOrCreate( |
||
| 26 | ['month' => $user->mth], |
||
| 27 | ['signups' => $user->num, 'sort_date' => $user->sort_date] |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | public static function getUsersByMonth(): array |
||
| 39 | } |
||
| 40 | } |
||
| 41 |