1 | <?php |
||||
2 | |||||
3 | namespace App\Models; |
||||
4 | |||||
5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
6 | use Illuminate\Database\Eloquent\Model; |
||||
7 | use Illuminate\Support\Facades\DB; |
||||
8 | |||||
9 | class ReleaseStat extends Model |
||||
10 | { |
||||
11 | use HasFactory; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
12 | |||||
13 | protected $guarded = []; |
||||
14 | |||||
15 | public static function insertRecentlyAdded(): void |
||||
16 | { |
||||
17 | $categories = Category::query()->with('parent')->where('r.adddate', '>', now()->subWeek())->select([ |
||||
18 | 'root_categories_id', DB::raw('COUNT(r.id) as count'), 'title', |
||||
19 | ])->join('releases as r', 'r.categories_id', '=', |
||||
20 | 'categories.id')->groupBy('title')->orderByDesc('count')->get(); |
||||
0 ignored issues
–
show
'count' 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
![]() |
|||||
21 | |||||
22 | foreach ($categories as $category) { |
||||
23 | // Check if we already have the information and if we do just update the count |
||||
24 | if (self::query()->where('category', $category->title)->exists()) { |
||||
25 | self::query()->where('category', $category->title)->update(['count' => $category->count]); |
||||
26 | |||||
27 | continue; |
||||
28 | } |
||||
29 | self::query()->create(['category' => $category->title, 'count' => $category->count]); |
||||
30 | } |
||||
31 | } |
||||
32 | |||||
33 | public static function getRecentlyAdded(): array |
||||
34 | { |
||||
35 | return self::query()->select(['category', 'count'])->get()->toArray(); |
||||
36 | } |
||||
37 | } |
||||
38 |