igaster / laravel-model-events

@@ -2,8 +2,7 @@
Loading
2 2
3 3
namespace Igaster\ModelEvents\Traits;
4 4
5 -
6 -
/**
5 +
/*
7 6
 * Add this trait to a Model to enable Log custom events.
8 7
 * It will log current auth user
9 8
 *
@@ -22,17 +21,13 @@
Loading
22 21
23 22
    public static function bootLogsModelEvents()
24 23
    {
25 -
26 24
        if (property_exists(self::class, 'logModelEvents')) {
27 -
28 25
            foreach (self::$logModelEvents as $eventName) {
29 -
30 26
                static::$eventName(function ($model) use ($eventName) {
31 27
                    $description = $eventName;
32 28
33 29
                    if ($eventName == 'updating' || $eventName == 'updated') {
34 30
                        if ($dirty = $model->getDirty()) {
35 -
36 31
                            $changed = [];
37 32
                            foreach ($dirty as $key => $value) {
38 33
                                if (!self::shouldHideKey($key)) {
@@ -52,7 +47,6 @@
Loading
52 47
53 48
                    $model->logModelEvent($description);
54 49
                });
55 -
56 50
            }
57 51
        }
58 52
    }
@@ -67,7 +61,6 @@
Loading
67 61
        return isset(self::$sanitizeUpdatedColumns) && in_array($key, self::$sanitizeUpdatedColumns);
68 62
    }
69 63
70 -
71 64
    // ----------------------------------------------
72 65
    //  Relationships
73 66
    // ----------------------------------------------
@@ -80,14 +73,13 @@
Loading
80 73
        return $this->morphMany(LogModelEvent::class, 'model');
81 74
    }
82 75
83 -
84 76
    // ----------------------------------------------
85 77
    //  Methods
86 78
    // ----------------------------------------------
87 79
88 80
    public function logModelEvent($description = '')
89 81
    {
90 -
        if (!$this->getKey()){
82 +
        if (!$this->getKey()) {
91 83
            return null;
92 84
        }
93 85
@@ -102,9 +94,10 @@
Loading
102 94
    public function getModelEvents($count = null)
103 95
    {
104 96
        $query = $this->modelEvents()->orderBy('id', 'desc');
105 -
        if($count) {
97 +
        if ($count) {
106 98
            $query->limit($count);
107 99
        }
100 +
108 101
        return $query->get();
109 102
    }
110 103
@@ -117,5 +110,4 @@
Loading
117 110
    {
118 111
        return $this->modelEvents()->delete();
119 112
    }
120 -
121 113
}

@@ -2,12 +2,11 @@
Loading
2 2
3 3
namespace Igaster\ModelEvents;
4 4
5 -
use Illuminate\Database\Eloquent\Model;
6 5
use Illuminate\Database\Eloquent\Builder;
6 +
use Illuminate\Database\Eloquent\Model;
7 7
8 8
class LogModelEvent extends Model
9 9
{
10 -
11 10
    protected $table = 'log_model_events';
12 11
    protected $guarded = [];
13 12
@@ -18,6 +17,7 @@
Loading
18 17
    public function user()
19 18
    {
20 19
        $userClass = config('auth.providers.users.model');
20 +
21 21
        return $this->belongsTo($userClass, 'user_id');
22 22
    }
23 23
@@ -30,11 +30,13 @@
Loading
30 30
    //  Scopes
31 31
    // ----------------------------------------------
32 32
33 -
    public function scopeWhereUser(Builder $query, $user){
33 +
    public function scopeWhereUser(Builder $query, $user)
34 +
    {
34 35
        return $query->where('user_id', $user->getKey());
35 36
    }
36 37
37 -
    public function scopeWhereModel(Builder $query, $model){
38 +
    public function scopeWhereModel(Builder $query, $model)
39 +
    {
38 40
        return $query->where([
39 41
            'model_type' => $model->getMorphClass(),
40 42
            'model_id' => $model->getKey(),
Files Complexity Coverage
src 36 66.67%
Project Totals (8 files) 36 66.67%
17.1
7.2=.2
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading