Completed
Push — master ( d065f1...f89ef3 )
by Richan
09:04
created

BlameableObserver::creating()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace RichanFongdasen\EloquentBlameable;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class BlameableObserver
8
{
9
    /**
10
     * Listening to any creating events.
11
     *
12
     * @param \Illuminate\Database\Eloquent\Model $model
13
     *
14
     * @return void
15
     */
16
    public function creating(Model $model)
17
    {
18
        app(BlameableService::class)->setAttribute($model, 'createdBy');
19
    }
20
21
    /**
22
     * Listening to any deleting events.
23
     *
24
     * @param \Illuminate\Database\Eloquent\Model $model
25
     *
26
     * @return void
27
     */
28
    public function deleting(Model $model)
29
    {
30
        app(BlameableService::class)->setAttribute($model, 'deletedBy');
31
32
        if ($model->isDirty()) {
33
            $model->silentUpdate();
1 ignored issue
show
Bug introduced by
The method silentUpdate() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean update()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
        }
35
    }
36
37
    /**
38
     * Listening to any restoring events.
39
     *
40
     * @param \Illuminate\Database\Eloquent\Model $model
41
     *
42
     * @return void
43
     */
44
    public function restoring(Model $model)
45
    {
46
        app(BlameableService::class)->setAttribute($model, 'deletedBy', true);
47
    }
48
49
    /**
50
     * Listening to any saving events.
51
     *
52
     * @param \Illuminate\Database\Eloquent\Model $model
53
     *
54
     * @return void
55
     */
56
    public function saving(Model $model)
57
    {
58
        app(BlameableService::class)->setAttribute($model, 'updatedBy');
59
    }
60
}
61