BlogCategoryObserver::deleting()   A
last analyzed

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
     * Handle the "deleting" event.
13
     */
14
    public function deleting(BlogCategory $blogCategory): void
15
    {
16
        // We need to do this to refresh the countable cache `blog_comment_count` of the user.
17
        $blogCategory->loadMissing('articles');
18
        foreach ($blogCategory->articles as $article) {
19
            $article->delete();
20
        }
21
    }
22
}
23