| 1 | <?php |
||
| 11 | class Notification extends Model |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $table = "app_notifications"; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | protected $fillable = ['user_id', 'type', 'message', 'link', 'readed_at']; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | protected $dates = ['created_at', 'updated_at', 'readed_at']; |
||
| 27 | |||
| 28 | protected $types = [ |
||
| 29 | 'success' => 'check', |
||
| 30 | 'info' => 'info', |
||
| 31 | 'danger' => 'times', |
||
| 32 | 'warning' => 'warning', |
||
| 33 | ]; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Filter by User |
||
| 37 | * @param $query |
||
| 38 | * @param $user |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function scopeByUser($query, $user) |
||
| 42 | { |
||
| 43 | return $query->where('user_id', $user->id); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Filter the Unread Ones |
||
| 48 | * @param $query |
||
| 49 | */ |
||
| 50 | public function scopeUnread($query) |
||
| 51 | { |
||
| 52 | $query->where('readed_at'); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return mixed |
||
| 57 | */ |
||
| 58 | public function getTimeAgo() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function getLink() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | public function getIconByType() |
||
| 81 | } |
||
| 82 |