1 | <?php |
||
24 | class Notification extends Model |
||
25 | { |
||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $fillable = [ |
||
30 | 'to_id', |
||
31 | 'to_type', |
||
32 | 'from_id', |
||
33 | 'from_type', |
||
34 | 'category_id', |
||
35 | 'read', |
||
36 | 'url', |
||
37 | 'extra', |
||
38 | 'expires_at', |
||
39 | 'stack_id', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $appends = [ |
||
46 | 'text', |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $casts = [ |
||
53 | 'extra' => 'array', |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * Notification constructor. |
||
58 | * |
||
59 | * @param array|\Fenos\Notifynder\Builder\Notification $attributes |
||
60 | */ |
||
61 | public function __construct($attributes = []) |
||
76 | |||
77 | /** |
||
78 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
79 | */ |
||
80 | public function category() |
||
84 | |||
85 | /** |
||
86 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo |
||
87 | */ |
||
88 | public function from() |
||
89 | { |
||
90 | if (notifynder_config()->isPolymorphic()) { |
||
91 | return $this->morphTo('from'); |
||
92 | } |
||
93 | |||
94 | return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'from_id'); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo |
||
99 | */ |
||
100 | public function to() |
||
108 | |||
109 | /** |
||
110 | * @return array |
||
111 | */ |
||
112 | public function getCustomFillableFields() |
||
116 | |||
117 | /** |
||
118 | * @return array |
||
119 | */ |
||
120 | protected function mergeFillables() |
||
126 | |||
127 | /** |
||
128 | * @return string |
||
129 | * @throws \Fenos\Notifynder\Exceptions\ExtraParamsException |
||
130 | */ |
||
131 | public function getTextAttribute() |
||
140 | |||
141 | /** |
||
142 | * @return bool|int |
||
143 | */ |
||
144 | public function read() |
||
148 | |||
149 | /** |
||
150 | * @return bool|int |
||
151 | */ |
||
152 | public function unread() |
||
156 | |||
157 | /** |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function resend() |
||
167 | |||
168 | /** |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function isAnonymous() |
||
175 | |||
176 | /** |
||
177 | * @param Builder $query |
||
178 | * @param $category |
||
179 | * @return Builder |
||
180 | */ |
||
181 | public function scopeByCategory(Builder $query, $category) |
||
187 | |||
188 | /** |
||
189 | * @param Builder $query |
||
190 | * @param int $read |
||
191 | * @return Builder |
||
192 | */ |
||
193 | public function scopeByRead(Builder $query, $read = 1) |
||
197 | } |
||
198 |