Passed
Push — 5.0.0 ( 49e1c0...87aae2 )
by Fèvre
06:22
created

BlogArticleObserver::creating()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Observers;
6
7
use Illuminate\Support\Facades\Auth;
8
use Xetaravel\Models\BlogArticle;
9
10
class BlogArticleObserver
11
{
12
    /**
13
     * Handle the "creating" event.
14
     */
15
    public function creating(BlogArticle $blogArticle): void
16
    {
17
        $blogArticle->user_id = Auth::id();
18
    }
19
20
    /**
21
     * Handle the "updating" event.
22
     */
23
    public function updating(BlogArticle $blogArticle): void
24
    {
25
        $blogArticle->generateSlug();
26
    }
27
28
    /**
29
     * Handle the "deleting" event.
30
     */
31
    public function deleting(BlogArticle $blogArticle): void
32
    {
33
        // We need to do this to refresh the countable cache `blog_comment_count` of the user.
34
        foreach ($blogArticle->comments as $comment) {
35
            $comment->delete();
36
        }
37
    }
38
}
39