Comment::entity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace jlourenco\comments\Models;
2
3
use Illuminate\Database\Eloquent\SoftDeletes;
4
use Illuminate\Database\Eloquent\Model;
5
use jlourenco\support\Traits\Creation;
6
use Sentinel;
7
8
class Comment extends Model
9
{
10
11
    /**
12
     * The database table used by the model.
13
     *
14
     * @var string
15
     */
16
    protected $table = 'Comment';
17
18
    /**
19
     * The attributes that are mass assignable.
20
     *
21
     * @var array
22
     */
23
    protected $fillable = ['comment'];
24
25
    /**
26
     * To allow soft deletes
27
     */
28
    use SoftDeletes;
29
30
    use Creation;
31
32
    /**
33
     * The User model name.
34
     *
35
     * @var string
36
     */
37
    protected static $usersModel = 'jlourenco\base\Models\BaseUser';
38
39
    /**
40
     * Returns the user model.
41
     *
42
     * @return string
43
     */
44
    public static function getUsersModel()
45
    {
46
        return static::$usersModel;
47
    }
48
49
    /**
50
     * Sets the user model.
51
     *
52
     * @param  string  $usersModel
53
     * @return void
54
     */
55
    public static function setUsersModel($usersModel)
56
    {
57
        static::$usersModel = $usersModel;
58
    }
59
60
    public function writter()
61
    {
62
        return $this->hasOne(static::$usersModel, 'id', 'created_by');
63
    }
64
65
    /**
66
     * Get all of the owning entity models.
67
     */
68
    public function entity()
69
    {
70
        return $this->morphTo();
71
    }
72
73
    /**
74
     * Get the user's first name.
75
     *
76
     * @param  string  $value
77
     * @return string
78
     */
79
    public function getCreatedByAttribute($value)
80
    {
81
        if ($value > 0)
82
            if ($user = Sentinel::findUserById($value))
83
                if ($user != null)
84
                    return $user;
85
86
        return $value;
87
    }
88
89
}
90