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 | /** |
||
65 | * Translate model to another language |
||
66 | * |
||
67 | * @param String $lang |
||
68 | * @param array $data |
||
69 | * @return Illuminate\Database\Eloquent\Model |
||
70 | */ |
||
71 | public function translateTo($lang, $data = []) |
||
91 | |||
92 | /** |
||
93 | * Checks if record has a translation |
||
94 | * |
||
95 | * @param String $lang |
||
96 | * @return Boolean |
||
97 | */ |
||
98 | public function hasTranslation($lang): bool |
||
105 | |||
106 | /** |
||
107 | * Undocumented function |
||
108 | * |
||
109 | * @param String $lang |
||
110 | * @return \Illuminate\Database\Eloquent\Builder |
||
111 | */ |
||
112 | private function getTranslationBaseQuery($lang): Builder |
||
118 | |||
119 | /** |
||
120 | * Get translation |
||
121 | * |
||
122 | * @param String $lang |
||
123 | * @return Illuminate\Database\Eloquent\Model|null |
||
124 | */ |
||
125 | public function translation($lang) |
||
129 | |||
130 | /* |
||
131 | * Return translation excluding the current language |
||
132 | * |
||
133 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
134 | */ |
||
135 | public function scopeWithTranslations(Builder $query, $lang = null, $fields = []) |
||
141 | |||
142 | /** |
||
143 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
144 | * @param string $lang |
||
145 | * |
||
146 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
147 | */ |
||
148 | public function scopeLang(Builder $query, $lang = null) |
||
152 | |||
153 | /** |
||
154 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
155 | * @param string $lang |
||
156 | * |
||
157 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
158 | */ |
||
159 | public function scopeNotLang(Builder $query, $lang = null) |
||
164 | |||
165 | /** |
||
166 | * Return only original rows |
||
167 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
168 | * |
||
169 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
170 | */ |
||
171 | public function scopeOnlyOriginal(Builder $query) |
||
175 | |||
176 | /* @param \Illuminate \Database \Eloquent \Builder $query |
||
177 | * |
||
178 | * @return \Illuminate\Database\Eloquent\Builder | static |
||
179 | */ |
||
180 | public function scopeOnlyOriginals(Builder $query) |
||
184 | } |
||
185 |
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.