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

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

81 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\Functions\Utility;
6
7 class Term extends Model
8 {
9 protected $table = 'fcom_terms';
10
11 protected $guarded = ['id'];
12
13 protected $fillable = [
14 'parent_id',
15 'taxonomy_name',
16 'slug',
17 'title',
18 'description',
19 'settings'
20 ];
21
22 protected $searchable = [
23 'title',
24 'description',
25 'slug'
26 ];
27
28 public static function boot()
29 {
30 parent::boot();
31
32 static::deleting(function ($term) {
33 $term->posts()->detach();
34 });
35 }
36
37 public function scopeSearchBy($query, $search)
38 {
39 if ($search) {
40 $fields = $this->searchable;
41 $query->where(function ($query) use ($fields, $search) {
42 $query->where(array_shift($fields), 'LIKE', "%$search%");
43 foreach ($fields as $field) {
44 $query->orWhere($field, 'LIKE', "$search%");
45 }
46 });
47 }
48
49 return $query;
50 }
51
52 public function posts()
53 {
54 return $this->belongsToMany(Feed::class, 'fcom_term_feed', 'term_id', 'post_id')
55 ->withoutGlobalScopes();
56 }
57
58 public function getSettingsAttribute($value)
59 {
60 $settings = Utility::safeUnserialize($value);
61
62 if (!$settings) {
63 $settings = [];
64 }
65
66 return $settings;
67 }
68
69 public function setSettingsAttribute($value)
70 {
71 $this->attributes['settings'] = maybe_serialize($value);
72 }
73
74 public function base_spaces()
75 {
76 return $this->belongsToMany(BaseSpace::class, 'fcom_meta', 'object_id', 'meta_key')
77 ->wherePivot('object_type', 'term_space_relation')
78 ->withoutGlobalScopes();
79 }
80 }
81