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 / Term.php

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

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