1 | <?php |
||||
2 | |||||
3 | namespace App\Models; |
||||
4 | |||||
5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
6 | use Illuminate\Database\Eloquent\Model; |
||||
7 | |||||
8 | class SignupStat extends Model |
||||
9 | { |
||||
10 | use HasFactory; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
11 | |||||
12 | protected $guarded = []; |
||||
13 | |||||
14 | public static function insertUsersByMonth(): void |
||||
15 | { |
||||
16 | $users = User::query()->whereNotNull('created_at')->where('created_at', '<>', '0000-00-00 00:00:00')->selectRaw("DATE_FORMAT(created_at, '%M %Y') as mth, COUNT(id) as num")->groupBy(['mth'])->orderByDesc('created_at')->get(); |
||||
0 ignored issues
–
show
'created_at' of type string is incompatible with the type Closure|Illuminate\Datab...\Database\Query\Builder expected by parameter $column of Illuminate\Database\Query\Builder::orderByDesc() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
17 | foreach ($users as $user) { |
||||
18 | self::updateOrCreate(['month' => $user->mth], ['signups' => $user->num]); |
||||
19 | } |
||||
20 | } |
||||
21 | |||||
22 | public static function getUsersByMonth(): array |
||||
23 | { |
||||
24 | return self::query()->select(['month', 'signups'])->get()->toArray(); |
||||
25 | } |
||||
26 | } |
||||
27 |