1 | <?php |
||
20 | trait TaxonomyTrait |
||
21 | { |
||
22 | /** |
||
23 | * Define a polymorphic many-to-many relationship. |
||
24 | * |
||
25 | * @param string $related |
||
26 | * @param string $name |
||
27 | * @param string $table |
||
28 | * @param string $foreignPivotKey |
||
29 | * @param string $relatedPivotKey |
||
30 | * @param string $parentKey |
||
31 | * @param string $relatedKey |
||
32 | * @param bool $inverse |
||
33 | * @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
||
34 | */ |
||
35 | abstract public function morphToMany( |
||
45 | |||
46 | /** |
||
47 | * Declared by Eloquent Model |
||
48 | */ |
||
49 | abstract public function getTable(); |
||
50 | |||
51 | /** |
||
52 | * Declared by Eloquent Model |
||
53 | */ |
||
54 | abstract public function getKey(); |
||
55 | |||
56 | /** |
||
57 | 24 | * The relation configuration |
|
58 | * |
||
59 | 24 | * @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
|
60 | */ |
||
61 | 24 | public function taxonomies() |
|
65 | |||
66 | /** |
||
67 | * Filter the model to return a subset of entries matching the term ID |
||
68 | * |
||
69 | * @param Builder $query |
||
70 | * @param int $term_id |
||
71 | * |
||
72 | 3 | * @return Builder |
|
73 | */ |
||
74 | public function scopeGetAllByTermId(Builder $query, $term_id) |
||
80 | |||
81 | /** |
||
82 | * Get the terms from a content |
||
83 | * |
||
84 | * @param int|string $vocabulary_id |
||
85 | 6 | * @return Collection |
|
86 | */ |
||
87 | 6 | public function getTerms($vocabulary_id) |
|
106 | |||
107 | /** |
||
108 | * Link a term to this content |
||
109 | * |
||
110 | 27 | * @param int $term_id |
|
111 | */ |
||
112 | 27 | public function addTerm($term_id) |
|
125 | |||
126 | /** |
||
127 | * Set the terms to a content, removes the old ones (only for one vocabulary if specified) |
||
128 | * |
||
129 | * @param array<integer> $terms |
||
130 | 24 | * @param int|string $vocabulary_id |
|
131 | */ |
||
132 | 24 | public function setTerms($terms, $vocabulary_id = null) |
|
140 | |||
141 | /** |
||
142 | * Removes terms specified by a vocabulary, or all |
||
143 | * |
||
144 | * @param int|string $vocabulary_id |
||
145 | 24 | * @return bool |
|
146 | */ |
||
147 | 24 | public function removeTerms($vocabulary_id = null) |
|
159 | |||
160 | /** |
||
161 | * Cache all terms of a content (only ids) |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 6 | private function cacheTermsForContent() |
|
186 | |||
187 | /** |
||
188 | * Get the cache key for this content |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | 24 | private function getTaxonomyCacheKey() |
|
196 | } |
||
197 |