1 | <?php |
||
30 | class Notification extends Model |
||
31 | { |
||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $fillable = [ |
||
36 | 'to_id', 'to_type', 'from_id', 'from_type', |
||
37 | 'category_id', 'read', 'url', 'extra', 'expire_time', |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * Notification constructor. |
||
42 | * |
||
43 | * @param array $attributes |
||
44 | */ |
||
45 | public function __construct(array $attributes = []) |
||
52 | |||
53 | /** |
||
54 | * Custom Collection. |
||
55 | * |
||
56 | * @param array $models |
||
57 | * @return NotifynderCollection|\Illuminate\Database\Eloquent\Collection |
||
58 | */ |
||
59 | public function newCollection(array $models = []) |
||
60 | { |
||
61 | return new NotifynderCollection($models); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
66 | */ |
||
67 | public function body() |
||
68 | { |
||
69 | return $this->belongsTo(NotificationCategory::class, 'category_id'); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo |
||
74 | */ |
||
75 | public function from() |
||
76 | { |
||
77 | // check if on the configurations file there is the option |
||
78 | // polymorphic set to true, if so Notifynder will work |
||
79 | // polymorphic. |
||
80 | if (config('notifynder.polymorphic') == false) { |
||
81 | return $this->belongsTo(config('notifynder.model'), 'from_id'); |
||
82 | } |
||
83 | |||
84 | return $this->morphTo(); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo |
||
89 | */ |
||
90 | public function to() |
||
91 | { |
||
92 | // check if on the configurations file there is the option |
||
93 | // polymorphic set to true, if so Notifynder will work |
||
94 | // polymorphic. |
||
95 | if (config('notifynder.polymorphic') == false) { |
||
96 | return $this->belongsTo(config('notifynder.model'), 'to_id'); |
||
97 | } |
||
98 | |||
99 | return $this->morphTo(); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Not read scope. |
||
104 | * |
||
105 | * @param $query |
||
106 | * @return mixed |
||
107 | */ |
||
108 | public function scopeWithNotRead($query) |
||
109 | { |
||
110 | return $query->where('read', 0); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Only Expired Notification scope. |
||
115 | * |
||
116 | * @param $query |
||
117 | * @return mixed |
||
118 | */ |
||
119 | public function scopeOnlyExpired($query) |
||
123 | |||
124 | /** |
||
125 | * Where Polymorphic. |
||
126 | * |
||
127 | * @param $query |
||
128 | * @param $toId |
||
129 | * @param $type |
||
130 | * @return mixed |
||
131 | */ |
||
132 | public function scopeWherePolymorphic($query, $toId, $type) |
||
133 | { |
||
134 | if (! $type or config('notifynder.polymorphic') === false) { |
||
135 | return $query->where('to_id', $toId); |
||
136 | } |
||
137 | |||
138 | return $query->where('to_id', $toId) |
||
139 | ->where('to_type', $type); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Get parsed body attributes. |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getNotifyBodyAttribute() |
||
148 | { |
||
149 | $notifynderParse = new NotifynderParser(); |
||
150 | |||
151 | return $notifynderParse->parse($this); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Get parsed body attributes. |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function getTextAttribute() |
||
163 | |||
164 | /** |
||
165 | * @param $value |
||
166 | * @return \Fenos\Notifynder\Notifications\ExtraParams |
||
167 | */ |
||
168 | public function getExtraAttribute($value) |
||
176 | |||
177 | /** |
||
178 | * Filter Scope by category. |
||
179 | * |
||
180 | * @param $query |
||
181 | * @param $category |
||
182 | * @return mixed |
||
183 | */ |
||
184 | public function scopeByCategory($query, $category) |
||
194 | |||
195 | /** |
||
196 | * Get custom required fields from the configs |
||
197 | * so that we can automatically bind them to the model |
||
198 | * fillable property. |
||
199 | * |
||
200 | * @return mixed |
||
201 | */ |
||
202 | public function getCustomFillableFields() |
||
210 | |||
211 | /** |
||
212 | * @return array |
||
213 | */ |
||
214 | protected function mergeFillable() |
||
220 | } |
||
221 |
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.