Completed
Push — issue-37 ( e24320...44d7c4 )
by Fèvre
03:48
created

Ruby::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 4
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Models;
3
4
use Illuminate\Support\Facades\Auth;
5
6 View Code Duplication
class Ruby extends Model
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
{
8
    /**
9
     * The attributes that are mass assignable.
10
     *
11
     * @var array
12
     */
13
    protected $fillable = [
14
        'user_id',
15
        'obtainable_id',
16
        'obtainable_type',
17
        'event_type',
18
        'data'
19
    ];
20
21
    /**
22
     * The attributes that should be cast to native types.
23
     *
24
     * @var array
25
     */
26
    protected $casts = [
27
        'data' => 'array'
28
    ];
29
30
    /**
31
     * The "booting" method of the model.
32
     *
33
     * @return void
34
     */
35
    protected static function boot()
36
    {
37
        parent::boot();
38
39
        // Set the user id to the new log before saving it.
40
        static::creating(function ($model) {
41
            $model->user_id = Auth::id();
42
        });
43
    }
44
45
    /**
46
     * Get the user that owns the log.
47
     *
48
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
49
     */
50
    public function user()
51
    {
52
        return $this->belongsTo(User::class);
53
    }
54
55
    /**
56
     * Get the obtainable relation.
57
     *
58
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
59
     */
60
    public function obtainable()
61
    {
62
        return $this->morphTo();
63
    }
64
}
65