Completed
Push — master ( 8f843b...36053e )
by Christopher
01:12
created

IsAuthorable::bootBelongsToUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Chriscreates\Blog\Traits;
4
5
use Illuminate\Support\Facades\Auth;
6
7
trait IsAuthorable
8
{
9
    public function author()
10
    {
11
        return $this->belongsTo(
0 ignored issues
show
Bug introduced by
The method belongsTo() does not exist on Chriscreates\Blog\Traits\IsAuthorable. Did you maybe mean bootBelongsToUser()?

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...
12
            config('blogs.user_class'),
13
            'user_id',
14
            config('blogs.user_key_name')
15
        );
16
    }
17
18
    public function user()
19
    {
20
        return $this->belongsTo(
0 ignored issues
show
Bug introduced by
The method belongsTo() does not exist on Chriscreates\Blog\Traits\IsAuthorable. Did you maybe mean bootBelongsToUser()?

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...
21
            config('blogs.user_class'),
22
            'user_id',
23
            config('blogs.user_key_name')
24
        );
25
    }
26
27
    public static function bootBelongsToUser()
28
    {
29
        static::saving(function ($model) {
30
            $model->user_id = $model->user_id ?? Auth::id();
31
        });
32
    }
33
}
34