1 | <?php |
||
18 | trait Translatable |
||
19 | { |
||
20 | protected $_deleting_translation = false; |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | public static function bootTranslatable() |
||
29 | |||
30 | /** |
||
31 | * Get the list of non translatable fields. |
||
32 | * |
||
33 | * @return array |
||
34 | */ |
||
35 | public function getNonTranslatable(): array |
||
39 | |||
40 | /** |
||
41 | * Get the list of fields to duplicate on create. |
||
42 | * (Other fields MUST BE nullable in database). |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function getOnCreateTranslatable(): array |
||
50 | |||
51 | /** |
||
52 | * Translation relationship. |
||
53 | * |
||
54 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
55 | */ |
||
56 | public function translation(): MorphOne |
||
60 | |||
61 | /** |
||
62 | * Return current item translations. |
||
63 | * |
||
64 | * @return \BBSLab\NovaTranslation\Models\TranslationRelation |
||
65 | */ |
||
66 | public function translations(): TranslationRelation |
||
70 | |||
71 | /** |
||
72 | * Create and return a translation entry for given locale ID. |
||
73 | * |
||
74 | * @param int $localeId |
||
75 | * @param int $translationId |
||
76 | * @return \BBSLab\NovaTranslation\Models\Translation |
||
77 | */ |
||
78 | public function upsertTranslationEntry(int $localeId, int $translationId = 0): Translation |
||
91 | |||
92 | /** |
||
93 | * Return next fresh translation ID. |
||
94 | * |
||
95 | * @return int |
||
96 | */ |
||
97 | public function freshTranslationId(): int |
||
105 | |||
106 | /** |
||
107 | * Scope a query to only retrieve items from given locale. |
||
108 | * |
||
109 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
110 | * @param string $iso |
||
111 | * @return \Illuminate\Database\Eloquent\Builder |
||
112 | */ |
||
113 | public function scopeLocale(EloquentBuilder $builder, string $iso = null) |
||
125 | |||
126 | /** |
||
127 | * Translate model to given locale and return translated model. |
||
128 | * |
||
129 | * @param \BBSLab\NovaTranslation\Models\Locale $locale |
||
130 | * @return \BBSLab\NovaTranslation\Models\Contracts\IsTranslatable |
||
131 | */ |
||
132 | public function translate(Locale $locale) |
||
154 | |||
155 | /** |
||
156 | * Set deleting translation state. |
||
157 | * |
||
158 | * @return void |
||
159 | */ |
||
160 | public function deletingTranslation(): void |
||
164 | |||
165 | /** |
||
166 | * Determine is the model currently in a delete translation process. |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function isDeletingTranslation(): bool |
||
174 | } |
||
175 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: