1 | <?php |
||
31 | class Notification extends Model |
||
32 | { |
||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $fillable = [ |
||
37 | 'to_id', |
||
38 | 'to_type', |
||
39 | 'from_id', |
||
40 | 'from_type', |
||
41 | 'category_id', |
||
42 | 'read', |
||
43 | 'url', |
||
44 | 'extra', |
||
45 | 'expire_time', |
||
46 | 'stack_id', |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * Notification constructor. |
||
51 | * |
||
52 | * @param array $attributes |
||
53 | */ |
||
54 | public function __construct(array $attributes = []) |
||
61 | |||
62 | /** |
||
63 | * Custom Collection. |
||
64 | * |
||
65 | * @param array $models |
||
66 | * @return NotifynderCollection|\Illuminate\Database\Eloquent\Collection |
||
67 | */ |
||
68 | public function newCollection(array $models = []) |
||
69 | { |
||
70 | return new NotifynderCollection($models); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
75 | */ |
||
76 | public function body() |
||
77 | { |
||
78 | return $this->belongsTo(NotificationCategory::class, 'category_id'); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo |
||
83 | */ |
||
84 | public function from() |
||
85 | { |
||
86 | // check if on the configurations file there is the option |
||
87 | // polymorphic set to true, if so Notifynder will work |
||
88 | // polymorphic. |
||
89 | if (config('notifynder.polymorphic') == false) { |
||
90 | return $this->belongsTo(config('notifynder.model'), 'from_id'); |
||
91 | } |
||
92 | |||
93 | return $this->morphTo(); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo |
||
98 | */ |
||
99 | public function to() |
||
100 | { |
||
101 | // check if on the configurations file there is the option |
||
102 | // polymorphic set to true, if so Notifynder will work |
||
103 | // polymorphic. |
||
104 | if (config('notifynder.polymorphic') == false) { |
||
105 | return $this->belongsTo(config('notifynder.model'), 'to_id'); |
||
106 | } |
||
107 | |||
108 | return $this->morphTo(); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Not read scope. |
||
113 | * |
||
114 | * @param $query |
||
115 | * @return mixed |
||
116 | */ |
||
117 | public function scopeWithNotRead($query) |
||
118 | { |
||
119 | return $query->where('read', 0); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Only Expired Notification scope. |
||
124 | * |
||
125 | * @param $query |
||
126 | * @return mixed |
||
127 | */ |
||
128 | public function scopeOnlyExpired($query) |
||
132 | |||
133 | /** |
||
134 | * Where Polymorphic. |
||
135 | * |
||
136 | * @param $query |
||
137 | * @param $toId |
||
138 | * @param $type |
||
139 | * @return mixed |
||
140 | */ |
||
141 | public function scopeWherePolymorphic($query, $toId, $type) |
||
150 | |||
151 | /** |
||
152 | * Get parsed body attributes. |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getNotifyBodyAttribute() |
||
157 | { |
||
158 | $notifynderParse = new NotifynderParser(); |
||
159 | |||
160 | return $notifynderParse->parse($this); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Get parsed body attributes. |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getTextAttribute() |
||
172 | |||
173 | /** |
||
174 | * @param $value |
||
175 | * @return \Fenos\Notifynder\Notifications\ExtraParams |
||
176 | */ |
||
177 | public function getExtraAttribute($value) |
||
185 | |||
186 | /** |
||
187 | * Filter Scope by category. |
||
188 | * |
||
189 | * @param $query |
||
190 | * @param $category |
||
191 | * @return mixed |
||
192 | */ |
||
193 | public function scopeByCategory($query, $category) |
||
203 | |||
204 | /** |
||
205 | * Get custom required fields from the configs |
||
206 | * so that we can automatically bind them to the model |
||
207 | * fillable property. |
||
208 | * |
||
209 | * @return mixed |
||
210 | */ |
||
211 | public function getCustomFillableFields() |
||
219 | |||
220 | /** |
||
221 | * @return array |
||
222 | */ |
||
223 | protected function mergeFillable() |
||
229 | |||
230 | /** |
||
231 | * Filter Scope by stack. |
||
232 | * |
||
233 | * @param $query |
||
234 | * @param $stackId |
||
235 | * @return mixed |
||
236 | */ |
||
237 | public function scopeByStack($query, $stackId) |
||
241 | |||
242 | /** |
||
243 | * Check if this notification is part of a stack. |
||
244 | * |
||
245 | * @return bool |
||
246 | */ |
||
247 | public function hasStack() |
||
251 | |||
252 | /** |
||
253 | * Get the full stack of notifications if this has one. |
||
254 | * |
||
255 | * @return null|Collection |
||
256 | */ |
||
257 | public function getStack() |
||
263 | } |
||
264 |
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.