Comment::user()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
9
namespace GitScrum\Models;
10
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Database\Eloquent\SoftDeletes;
13
use Carbon\Carbon;
14
use GitScrum\Scopes\GlobalScope;
15
16
class Comment extends Model
17
{
18
    use SoftDeletes;
19
    use GlobalScope;
20
    
21
    /**
22
     * The database table used by the model.
23
     *
24
     * @var string
25
     */
26
    protected $table = 'comments';
27
28
    /**
29
     * Attributes that should be mass-assignable.
30
     *
31
     * @var array
32
     */
33
    protected $fillable = ['commentable_type', 'commentable_id', 'user_id', 'comment'];
34
35
    /**
36
     * The attributes excluded from the model's JSON form.
37
     *
38
     * @var array
39
     */
40
    protected $hidden = [];
41
42
    /**
43
     * The attributes that should be casted to native types.
44
     *
45
     * @var array
46
     */
47
    protected $casts = [];
48
49
    protected $dates = ['deleted_at'];
50
51
    protected static function boot()
52
    {
53
        parent::boot();
54
    }
55
56
    public function user()
57
    {
58
        return $this->belongsTo(\GitScrum\Models\User::class, 'user_id', 'id');
59
    }
60
61
    public function issue()
62
    {
63
        return $this->belongsTo(\GitScrum\Models\Issue::class, 'commentable_id', 'id');
64
    }
65
66
    public function statuses()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
67
    {
68
        return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable')
69
            ->orderby('created_at', 'DESC');
70
    }
71
72
    public function getDateforhumansAttribute()
73
    {
74
        return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['created_at'])->diffForHumans();
75
    }
76
}
77