Passed
Push — master ( f1a782...17ae54 )
by Ion
04:19 queued 45s
created

UserTask::getDeadlineAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
9
/**
10
 * Class UserTask
11
 *
12
 * @property int $id
13
 * @property int $user_id
14
 * @property int $assigned_user_id
15
 * @property string $description
16
 * @property Carbon $deadline
17
 * @property int $status
18
 * @property Carbon|null $created_at
19
 * @property Carbon|null $updated_at
20
 * @property Carbon|null $deleted_at
21
 *
22
 * @property-read User $user
23
 * @property-read User $assignedUser
24
 *
25
 * @package App\Models
26
 */
27
class UserTask extends Model
28
{
29
    use SoftDeletes;
30
31
    /** @var int */
32
    const STATUS_ASSIGNED = 0;
33
34
    /** @var int */
35
    const STATUS_COMPLETED = 1;
36
37
    /** @var bool */
38
    public $timestamps = true;
39
40
    /** @var string */
41
    protected $table = 'user_tasks';
42
43
    /** @var array */
44
    protected $fillable = [
45
        'user_id',
46
        'assigned_user_id',
47
        'description',
48
        'deadline',
49
        'status'
50
    ];
51
52
    /** @var array */
53
    protected $visible = [
54
        'id',
55
        'user_id',
56
        'assigned_user_id',
57
        'description',
58
        'deadline',
59
        'status',
60
        'created_at',
61
        'updated_at',
62
        'user',
63
        'assignedUser'
64
    ];
65
66
    /** @var array */
67
    protected $casts = [
68
        'status' => 'int'
69
    ];
70
71
    /** @var array */
72
    protected $sortable = [
73
        'id',
74
        'description',
75
        'deadline',
76
        'status',
77
        'created_at',
78
        'updated_at',
79
    ];
80
81
    /** @var array */
82
    protected $searchable = [
83
        'description'
84
    ];
85
86
    /** @var array */
87
    protected $filterable = [
88
        'user_id',
89
        'status'
90
    ];
91
92
    /**
93
     * User.
94
     *
95
     * @return BelongsTo
96
     */
97
    public function user()
98
    {
99
        return $this->belongsTo(User::class, 'user_id', 'id');
100
    }
101
102
    /**
103
     * User assigned.
104
     *
105
     * @return BelongsTo
106
     */
107
    public function assignedUser()
108
    {
109
        return $this->belongsTo(User::class, 'assigned_user_id', 'id');
110
    }
111
112
    /**
113
     * @param $value
114
     *
115
     * @return Carbon
116
     */
117
    public function getDeadlineAttribute($value)
118
    {
119
        return Carbon::parse($value);
120
    }
121
}
122