| 1 | <?php |
||
| 7 | class Notification extends Model |
||
| 8 | { |
||
| 9 | |||
| 10 | /** |
||
| 11 | * The table associated with the model. |
||
| 12 | * |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $table = 'notifications'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The primary key column name. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $primaryKey = 'notifications_id'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Indicates if the model should be timestamped. |
||
| 26 | * |
||
| 27 | * @var bool |
||
| 28 | */ |
||
| 29 | public $timestamps = false; |
||
| 30 | |||
| 31 | public function scopeIsUnread($query) |
||
| 32 | { |
||
| 33 | return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->whereNull('user_id')->orWhere(['key'=>'sticky', 'value'=> 1])->limit(); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function scopeIsArchived($query, $request) |
||
| 37 | { |
||
| 38 | $user_id = $request->user()->user_id; |
||
| 39 | return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->where('user_id', $user_id)->where(['key'=>'read', 'value'=> 1])->limit(); |
||
| 40 | } |
||
| 41 | |||
| 42 | public function scopeLimit($query) |
||
| 46 | |||
| 47 | public function users() { |
||
| 50 | |||
| 51 | } |
||
| 52 |