Notification::getTimeAgoAttribute()   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
namespace Modules\Notification\Entities;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * @property string type
9
 * @property string message
10
 * @property string icon_class
11
 * @property string title
12
 * @property string link
13
 * @property bool is_read
14
 * @property \Carbon\Carbon created_at
15
 * @property \Carbon\Carbon updated_at
16
 * @property int user_id
17
 */
18
class Notification extends Model
19
{
20
    protected $table = 'notification__notifications';
21
    protected $fillable = ['user_id', 'type', 'message', 'icon_class', 'link', 'is_read', 'title'];
22
    protected $appends = ['time_ago'];
23
    protected $casts = ['is_read' => 'bool'];
24
25
    /**
26
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
27
     */
28
    public function user()
29
    {
30
        $driver = config('asgard.user.config.driver');
31
32
        return $this->belongsTo("Modules\\User\\Entities\\{$driver}\\User");
33
    }
34
35
    /**
36
     * Return the created time in difference for humans (2 min ago)
37
     * @return string
38
     */
39
    public function getTimeAgoAttribute()
40
    {
41
        return $this->created_at->diffForHumans();
42
    }
43
44
    public function isRead() : bool
45
    {
46
        return $this->is_read === true;
47
    }
48
}
49