NNTmux /
newznab-tmux
| 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
Loading history...
|
|||||
| 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 |
||||
| 33 | { |
||||
| 34 | return self::query() |
||||
| 35 | ->select(['month', 'signups']) |
||||
| 36 | ->orderByDesc('sort_date') |
||||
|
0 ignored issues
–
show
'sort_date' 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
Loading history...
|
|||||
| 37 | ->get() |
||||
| 38 | ->toArray(); |
||||
| 39 | } |
||||
| 40 | } |
||||
| 41 |