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 GitScrum\Scopes\GlobalScope; |
14
|
|
|
|
15
|
|
|
class Note extends Model |
16
|
|
|
{ |
17
|
|
|
use SoftDeletes; |
18
|
|
|
use GlobalScope; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The database table used by the model. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $table = 'notes'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Attributes that should be mass-assignable. |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $fillable = ['noteable_type', 'noteable_id', 'user_id', |
33
|
|
|
'slug', 'title', 'position', 'closed_at', ]; |
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
|
|
|
/** |
50
|
|
|
* The attributes that should be mutated to dates. |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
protected $dates = ['deleted_at']; |
55
|
|
|
|
56
|
|
|
protected static function boot() |
57
|
|
|
{ |
58
|
|
|
parent::boot(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function noteable() |
62
|
|
|
{ |
63
|
|
|
return $this->morphTo('noteable'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function statuses() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable') |
69
|
|
|
->orderby('created_at', 'DESC'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function closedUser() |
73
|
|
|
{ |
74
|
|
|
return $this->belongsTo(\GitScrum\Models\User::class, 'closed_user_id', 'id'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setClosedUserIdAttribute($value) |
78
|
|
|
{ |
79
|
|
|
$this->attributes['closed_user_id'] = is_null($this->closed_at) ? $value : null; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setClosedAtAttribute($value) |
83
|
|
|
{ |
84
|
|
|
$this->attributes['closed_at'] = is_null($this->closed_at) ? $value : null; |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.