1 | <?php |
||
27 | trait RelationTrait |
||
28 | { |
||
29 | /** |
||
30 | * An issue has one user assigned to (inverse relationship of User::issues). |
||
31 | * |
||
32 | * @return Relations\BelongsTo |
||
33 | */ |
||
34 | public function assigned() |
||
35 | { |
||
36 | return $this->belongsTo('Tinyissue\Model\User', 'assigned_to'); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * An issue has one user updated by (inverse relationship of User::issuesUpdatedBy). |
||
41 | * |
||
42 | * @return Relations\BelongsTo |
||
43 | */ |
||
44 | public function updatedBy() |
||
45 | { |
||
46 | return $this->belongsTo('Tinyissue\Model\User', 'updated_by'); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * An issue has one user closed it (inverse relationship of User::issuesClosedBy). |
||
51 | * |
||
52 | * @return Relations\BelongsTo |
||
53 | */ |
||
54 | public function closer() |
||
58 | |||
59 | /** |
||
60 | * An issue has one user created it (inverse relationship of User::issuesCreatedBy). |
||
61 | * |
||
62 | * @return Relations\BelongsTo |
||
63 | */ |
||
64 | public function user() |
||
65 | { |
||
66 | return $this->belongsTo('Tinyissue\Model\User', 'created_by'); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Issue belong to a project. |
||
71 | * |
||
72 | * @return Relations\BelongsTo |
||
73 | */ |
||
74 | public function project() |
||
75 | { |
||
76 | return $this->belongsTo('Tinyissue\Model\Project'); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Issue can have many attachments. |
||
81 | * |
||
82 | * @return Relations\HasMany |
||
83 | */ |
||
84 | public function attachments() |
||
85 | { |
||
86 | return $this |
||
87 | ->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'issue_id') |
||
88 | ->where(function (Builder $query) { |
||
89 | $query->where('comment_id', '=', 0); |
||
90 | $query->orWhere('comment_id', '=', null); |
||
91 | }); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Issue have many users activities. |
||
96 | * |
||
97 | * @return Relations\HasMany |
||
98 | */ |
||
99 | public function activities() |
||
100 | { |
||
101 | return $this |
||
102 | ->hasMany('Tinyissue\Model\User\Activity', 'item_id') |
||
103 | ->orderBy('created_at', 'ASC'); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Issue have many users activities (all except comments). |
||
108 | * |
||
109 | * @return mixed |
||
110 | */ |
||
111 | public function generalActivities() |
||
112 | { |
||
113 | return $this |
||
114 | ->hasMany('Tinyissue\Model\User\Activity', 'item_id') |
||
115 | ->whereNotIn('type_id', [Model\Activity::TYPE_COMMENT]) |
||
116 | ->orderBy('created_at', 'ASC'); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Issue have many users activities (comments). |
||
121 | * |
||
122 | * @return mixed |
||
123 | */ |
||
124 | public function commentActivities() |
||
125 | { |
||
126 | return $this |
||
127 | ->hasMany('Tinyissue\Model\User\Activity', 'item_id') |
||
128 | ->whereIn('type_id', [Model\Activity::TYPE_COMMENT]) |
||
129 | ->orderBy('created_at', 'ASC'); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Issue have many tags. |
||
134 | * |
||
135 | * @return Relations\BelongsToMany |
||
136 | */ |
||
137 | 1 | public function tags() |
|
141 | |||
142 | /** |
||
143 | * Issue have many comments. |
||
144 | * |
||
145 | * @return Relations\HasMany |
||
146 | */ |
||
147 | public function comments() |
||
148 | { |
||
149 | return $this |
||
153 | |||
154 | /** |
||
155 | * Issue can have many messages queue. |
||
156 | * |
||
157 | * @return Relations\HasMany |
||
158 | */ |
||
159 | public function messagesQueue() |
||
163 | } |
||
164 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.