1 | <?php |
||
11 | trait Translatable |
||
12 | { |
||
13 | abstract public function getKeyName(); |
||
14 | |||
15 | /** |
||
16 | * @return void |
||
17 | */ |
||
18 | public static function bootTranslatable(): void |
||
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getLangKey(): String |
||
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | public function getForeignKey(): String |
||
55 | |||
56 | /** |
||
57 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
58 | */ |
||
59 | public function translations() |
||
63 | |||
64 | // public function original() |
||
65 | // { |
||
66 | // return $this->belongsTo(get_class($this), 'profile_id', 'id'); |
||
67 | // } |
||
68 | |||
69 | /** |
||
70 | * Determin fields to be excluded from the translation |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | private function fieldsToExclude(): array |
||
86 | |||
87 | /** |
||
88 | * Translate model to another language |
||
89 | * |
||
90 | * @param String $lang |
||
91 | * @param array $data |
||
92 | * @return Illuminate\Database\Eloquent\Model |
||
93 | */ |
||
94 | public function translateTo($lang, $data = []) |
||
113 | |||
114 | /** |
||
115 | * Checks if record has a translation |
||
116 | * |
||
117 | * @param String $lang |
||
118 | * @return Boolean |
||
119 | */ |
||
120 | public function hasTranslation($lang): bool |
||
127 | |||
128 | /** |
||
129 | * Undocumented function |
||
130 | * |
||
131 | * @param String $lang |
||
132 | * @return \Illuminate\Database\Eloquent\Builder |
||
133 | */ |
||
134 | private function getTranslationBaseQuery($lang): Builder |
||
140 | |||
141 | /** |
||
142 | * Get translation |
||
143 | * |
||
144 | * @param String $lang |
||
145 | * @return Illuminate\Database\Eloquent\Model|null |
||
146 | */ |
||
147 | public function translation($lang) |
||
151 | |||
152 | /* |
||
153 | * Return translation excluding the current language |
||
154 | * |
||
155 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
156 | */ |
||
157 | public function scopeWithTranslations(Builder $query, $lang = null, $fields = []) |
||
163 | |||
164 | /** |
||
165 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
166 | * @param string $lang |
||
167 | * |
||
168 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
169 | */ |
||
170 | public function scopeLang(Builder $query, $lang = null) |
||
174 | |||
175 | /** |
||
176 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
177 | * @param string $lang |
||
178 | * |
||
179 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
180 | */ |
||
181 | public function scopeNotLang(Builder $query, $lang = null) |
||
186 | |||
187 | /** |
||
188 | * Return only original rows |
||
189 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
190 | * |
||
191 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
192 | */ |
||
193 | public function scopeOnlyOriginal(Builder $query) |
||
197 | |||
198 | /* @param \Illuminate \Database \Eloquent \Builder $query |
||
199 | * |
||
200 | * @return \Illuminate\Database\Eloquent\Builder | static |
||
201 | */ |
||
202 | public function scopeOnlyOriginals(Builder $query) |
||
206 | } |
||
207 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.