Completed
Push — issue-37 ( 681eed )
by Fèvre
03:10
created

UserRuby::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Models;
3
4
use Illuminate\Support\Facades\Auth;
5
use Xetaravel\Models\Presenters\UserRubyPresenter;
6
7
class UserRuby extends Model
8
{
9
    use UserRubyPresenter;
10
11
    /**
12
     * The attributes that are mass assignable.
13
     *
14
     * @var array
15
     */
16
    protected $fillable = [
17
        'user_id',
18
        'obtainable_id',
19
        'obtainable_type'
20
    ];
21
22
    /**
23
     * The "booting" method of the model.
24
     *
25
     * @return void
26
     */
27
    protected static function boot()
28
    {
29
        parent::boot();
30
31
        // Set the user id to the new log before saving it.
32
        static::creating(function ($model) {
33
            $model->user_id = Auth::id();
34
        });
35
    }
36
37
    /**
38
     * Get the user that owns the log.
39
     *
40
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
41
     */
42
    public function user()
43
    {
44
        return $this->belongsTo(User::class);
45
    }
46
47
    /**
48
     * Get the obtainable relation.
49
     *
50
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
51
     */
52
    public function obtainable()
53
    {
54
        return $this->morphTo();
55
    }
56
}
57