1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
# == Schema Information |
13
|
|
|
# |
14
|
|
|
# Table name: comments |
15
|
|
|
# |
16
|
|
|
# id :integer not null, primary key |
17
|
|
|
# message :text |
18
|
|
|
# target_type :string(255) |
19
|
|
|
# author_id :integer |
20
|
|
|
# created_at :timestamp |
21
|
|
|
# updated_at :timestamp |
22
|
|
|
# project_id :integer |
23
|
|
|
# attachment :string(255) |
24
|
|
|
# line_code :string(255) |
25
|
|
|
# commit_id :string(255) |
26
|
|
|
# target_id :integer |
27
|
|
|
# system :boolean default(FALSE), not null |
28
|
|
|
# st_diff :text |
29
|
|
|
# updated_by_id :integer |
30
|
|
|
# is_award :boolean |
31
|
|
|
# |
32
|
|
|
|
33
|
|
|
namespace Gitamin\Models; |
34
|
|
|
|
35
|
|
|
use AltThree\Validator\ValidatingTrait; |
36
|
|
|
use Gitamin\Presenters\CommentPresenter; |
37
|
|
|
use Illuminate\Database\Eloquent\Model; |
38
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
39
|
|
|
use McCool\LaravelAutoPresenter\HasPresenter; |
40
|
|
|
|
41
|
|
|
class Comment extends Model implements HasPresenter |
42
|
|
|
{ |
43
|
|
|
use SoftDeletes, ValidatingTrait; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The attributes that should be casted to native types. |
47
|
|
|
* |
48
|
|
|
* @var string[] |
49
|
|
|
*/ |
50
|
|
|
protected $casts = [ |
51
|
|
|
'id' => 'int', |
52
|
|
|
'deleted_at' => 'date', |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The fillable properties. |
57
|
|
|
* |
58
|
|
|
* @var string[] |
59
|
|
|
*/ |
60
|
|
|
protected $fillable = [ |
61
|
|
|
'message', |
62
|
|
|
'target_type', |
63
|
|
|
'target_id', |
64
|
|
|
'author_id', |
65
|
|
|
'project_id', |
66
|
|
|
'created_at', |
67
|
|
|
'updated_at', |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The validation rules. |
72
|
|
|
* |
73
|
|
|
* @var string[] |
74
|
|
|
*/ |
75
|
|
|
public $rules = [ |
76
|
|
|
'author_id' => 'int', |
77
|
|
|
'project_id' => 'int', |
78
|
|
|
'message' => 'required', |
79
|
|
|
'target_type' => 'string|required', |
80
|
|
|
'target_id' => 'int', |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* A comment belongs to a project. |
85
|
|
|
* |
86
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
87
|
|
|
*/ |
88
|
|
|
public function project() |
89
|
|
|
{ |
90
|
|
|
return $this->belongsTo(Project::class, 'project_id', 'id'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Moments can belong to a target. |
95
|
|
|
* |
96
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
97
|
|
|
*/ |
98
|
|
|
public function target() |
99
|
|
|
{ |
100
|
|
|
return $this->belongsTo('Gitamin\\Models\\'.$this->target_type, 'target_id', 'id'); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get the presenter class. |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getPresenterClass() |
109
|
|
|
{ |
110
|
|
|
return CommentPresenter::class; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.