1 | <?php |
||
18 | trait Translatable |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | public static function bootTranslatable() |
||
24 | { |
||
25 | static::observe(TranslatableObserver::class); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Get the list of non translatable fields. |
||
30 | * |
||
31 | * @return array |
||
32 | */ |
||
33 | public function getNonTranslatable(): array |
||
37 | |||
38 | /** |
||
39 | * Get the list of fields to duplicate on create. |
||
40 | * (Other fields MUST BE nullable in database). |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | public function getOnCreateTranslatable(): array |
||
48 | |||
49 | /** |
||
50 | * Translation relationship. |
||
51 | * |
||
52 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
53 | */ |
||
54 | public function translation(): MorphOne |
||
58 | |||
59 | /** |
||
60 | * Return current item translations. |
||
61 | * |
||
62 | * @return \Illuminate\Database\Eloquent\Collection|self[] |
||
63 | */ |
||
64 | public function translations(): Collection |
||
75 | |||
76 | /** |
||
77 | * Create and return a translation entry for given locale ID. |
||
78 | * |
||
79 | * @param int $localeId |
||
80 | * @param int $translationId |
||
81 | * @return \BBSLab\NovaTranslation\Models\Translation |
||
82 | */ |
||
83 | public function upsertTranslationEntry(int $localeId, int $translationId = 0): Translation |
||
96 | |||
97 | /** |
||
98 | * Return next fresh translation ID. |
||
99 | * |
||
100 | * @return int |
||
101 | */ |
||
102 | public function freshTranslationId(): int |
||
110 | |||
111 | /** |
||
112 | * Scope a query to only retrieve items from given locale. |
||
113 | * |
||
114 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
115 | * @param string $iso |
||
116 | * @return \Illuminate\Database\Eloquent\Builder |
||
117 | */ |
||
118 | public function scopeLocale(EloquentBuilder $builder, string $iso = null) |
||
130 | |||
131 | /** |
||
132 | * Translate model to given locale and return translated model. |
||
133 | * |
||
134 | * @param \BBSLab\NovaTranslation\Models\Locale $locale |
||
135 | * @return \BBSLab\NovaTranslation\Models\Contracts\IsTranslatable |
||
136 | */ |
||
137 | public function translate(Locale $locale) |
||
156 | } |
||
157 |
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: