PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.01
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Models / NotificationSubscriber.php

NotificationSubscriber.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.10.01, at app/Models/NotificationSubscriber.php

78 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Models;
4
5 use FluentCommunity\App\Models\XProfile;
6
7 /**
8 * Meta Model - DB Model for Notifications table
9 *
10 * Database Model
11 *
12 * @package FluentCommunity\App\Models
13 *
14 * @version 1.0.0
15 */
16 class NotificationSubscriber extends Model
17 {
18 protected $table = 'fcom_notification_users';
19
20 protected $primaryKey = 'id';
21
22 protected $guarded = ['id'];
23
24 protected $fillable = [
25 'object_id',
26 'user_id',
27 'is_read',
28 'object_type',
29 'notification_type'
30 ];
31
32 protected static function boot()
33 {
34 parent::boot();
35
36 static::creating(function ($model) {
37 $model->object_type = 'notification';
38 $model->notification_type = 'web';
39 });
40
41 static::updating(function ($model) {
42 $model->object_type = 'notification';
43 $model->notification_type = 'web';
44 });
45
46 // Add global scope to get only notifications
47 static::addGlobalScope('notification', function ($builder) {
48 $builder->where('object_type', 'notification');
49 });
50 }
51
52 public function user()
53 {
54 return $this->belongsTo(User::class, 'user_id');
55 }
56
57 public function xprofile()
58 {
59 return $this->belongsTo(XProfile::class, 'user_id', 'user_id');
60 }
61
62 public function notification()
63 {
64 return $this->belongsTo(Notification::class, 'object_id');
65 }
66
67 public function scopeUnread($query)
68 {
69 return $query->where('is_read', 0);
70 }
71
72 public function scopeRead($query)
73 {
74 return $query->where('is_read', 1);
75 }
76
77 }
78