| Conditions | 2 |
| Paths | 2 |
| Total Lines | 14 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | ); |
||
| 41 |