1 | <?php |
||
11 | trait Translatable |
||
12 | { |
||
13 | /** |
||
14 | * @return void |
||
15 | */ |
||
16 | public static function bootTranslatable(): void |
||
37 | |||
38 | /** |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getLangKey(): String |
||
45 | |||
46 | /** |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getForeignKey(): String |
||
53 | |||
54 | /** |
||
55 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
56 | */ |
||
57 | public function translations() |
||
61 | |||
62 | /** |
||
63 | * Translate model to another language |
||
64 | * |
||
65 | * @param String $lang |
||
66 | * @param array $data |
||
67 | * @return Illuminate\Database\Eloquent\Model |
||
68 | */ |
||
69 | public function translateTo($lang, $data = []) |
||
89 | |||
90 | /** |
||
91 | * Checks if record has a translation |
||
92 | * |
||
93 | * @param String $lang |
||
94 | * @return Model|null |
||
95 | */ |
||
96 | public function hasTranslation($lang) |
||
107 | |||
108 | /** |
||
109 | * Get translation |
||
110 | * |
||
111 | * @param String $lang |
||
112 | * @return Model|null |
||
113 | */ |
||
114 | public function translation($lang) |
||
121 | |||
122 | /* |
||
123 | * Return translation excluding the current language |
||
124 | * |
||
125 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
126 | */ |
||
127 | public function scopeWithTranslations(Builder $query, $lang = null, $fields = []) |
||
133 | |||
134 | /** |
||
135 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
136 | * @param string $lang |
||
137 | * |
||
138 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
139 | */ |
||
140 | public function scopeLang(Builder $query, $lang = null) |
||
144 | |||
145 | /** |
||
146 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
147 | * @param string $lang |
||
148 | * |
||
149 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
150 | */ |
||
151 | public function scopeNotLang(Builder $query, $lang = null) |
||
156 | |||
157 | /** |
||
158 | * Return only original rows |
||
159 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
160 | * |
||
161 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
162 | */ |
||
163 | public function scopeOnlyOriginal(Builder $query) |
||
167 | |||
168 | /* @param \Illuminate \Database \Eloquent \Builder $query |
||
169 | * |
||
170 | * @return \Illuminate\Database\Eloquent\Builder | static |
||
171 | */ |
||
172 | public function scopeOnlyOriginals(Builder $query) |
||
176 | } |
||
177 |
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.