Passed
Push — 5.0.0 ( 757365...6c4e14 )
by Fèvre
05:11
created

BlogCategoryObserver::deleting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Observers;
6
7
use Xetaravel\Models\BlogCategory;
8
9
class BlogCategoryObserver
10
{
11
12
    /**
13
     * Handle the "deleting" event.
14
     */
15
    public function deleting(BlogCategory $blogCategory): void
16
    {
17
        // We need to do this to refresh the countable cache `blog_comment_count` of the user.
18
        $blogCategory->loadMissing('articles');
19
        foreach ($blogCategory->articles as $article) {
20
            $article->delete();
21
        }
22
    }
23
}
24