Conditions | 3 |
Paths | 3 |
Total Lines | 15 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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(); |
||
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 | } |
||
38 |