PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.0
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 / Reaction.php

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

92 lines 1.8 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\Model;
6 use FluentCommunity\App\Models\XProfile;
7
8 class Reaction extends Model
9 {
10 protected $table = 'fcom_post_reactions';
11
12 protected $guarded = ['id'];
13
14 protected $fillable = [
15 'user_id',
16 'object_id',
17 'object_type',
18 'type',
19 'ip_address',
20 'parent_id',
21 'created_at',
22 'updated_at'
23 ];
24
25 protected $hidden = ['ip_address'];
26
27 protected $searchable = [
28 'message'
29 ];
30
31 public static function boot()
32 {
33 parent::boot();
34
35 static::creating(function ($model) {
36
37 if (empty($model->user_id)) {
38 $model->user_id = get_current_user_id();
39 }
40
41 if (empty($model->object_type)) {
42 $model->object_type = 'feed';
43 }
44
45 if (empty($model->type)) {
46 $model->type = 'like';
47 }
48
49 });
50 }
51
52 public function scopeTypeBy($query, $type = 'like')
53 {
54 if ($type) {
55 $query->where('type', $type);
56 }
57
58 return $query;
59 }
60
61 public function scopeObjectType($query, $type = 'feed')
62 {
63 if ($type) {
64 $query->where('object_type', $type);
65 }
66
67 return $query;
68 }
69
70 public function user()
71 {
72 return $this->belongsTo(User::class, 'user_id', 'ID');
73 }
74
75 public function xprofile()
76 {
77 return $this->belongsTo(XProfile::class, 'user_id', 'user_id');
78 }
79
80 public function feed()
81 {
82 return $this->belongsTo(Feed::class, 'object_id', 'id')
83 ->where('object_type', 'feed');
84 }
85
86 public function comment()
87 {
88 return $this->belongsTo(Comment::class, 'object_id', 'id')
89 ->where('object_type', 'comment');
90 }
91 }
92