1
1
<?php
2
2
3
-
4
3
namespace Despark \LaravelDbLocalization \Traits ;
5
4
6
-
7
5
use Despark \LaravelDbLocalization \Models \TranslationModel ;
8
6
use Despark \LaravelDbLocalization \Observers \ModelObserver ;
9
7
@@ -33,7 +31,7 @@ trait HasTranslation
33
31
protected $ activeLocale ;
34
32
35
33
/**
36
- * Bootstrap the trait
34
+ * Bootstrap the trait.
37
35
*/
38
36
public static function bootHasTranslation ()
39
37
{
@@ -51,8 +49,9 @@ public function translation()
51
49
/**
52
50
* Create a new instance of the given model.
53
51
*
54
- * @param array $attributes
55
- * @param bool $exists
52
+ * @param array $attributes
53
+ * @param bool $exists
54
+ *
56
55
* @return static
57
56
*/
58
57
public function newInstance ($ attributes = [], $ exists = false )
@@ -67,14 +66,14 @@ public function newInstance($attributes = [], $exists = false)
67
66
* Create a new model instance for a related model.
68
67
* We overwrite this so we can dynamically create the table on the related model.
69
68
*
70
- * @param string $class
69
+ * @param string $class
70
+ *
71
71
* @return mixed
72
72
*/
73
73
protected function newRelatedInstance ($ class )
74
74
{
75
-
76
75
if (is_a ($ class , TranslationModel::class, true )) {
77
- return tap (new $ class , function ($ instance ) {
76
+ return tap (new $ class() , function ($ instance ) {
78
77
$ instance ->setTable ($ this ->getTranslationTable ());
79
78
80
79
if (! $ instance ->getConnectionName ()) {
@@ -83,7 +82,7 @@ protected function newRelatedInstance($class)
83
82
});
84
83
}
85
84
86
- return tap (new $ class , function ($ instance ) {
85
+ return tap (new $ class() , function ($ instance ) {
87
86
if (! $ instance ->getConnectionName ()) {
88
87
$ instance ->setConnection ($ this ->connection );
89
88
}
@@ -92,7 +91,6 @@ protected function newRelatedInstance($class)
92
91
93
92
/**
94
93
* @param string $key
95
- * @return null
96
94
*/
97
95
public function getAttribute ($ key )
98
96
{
@@ -118,10 +116,10 @@ public function setTranslation($key, $locale, $value)
118
116
$ this ->translatedAttributes [$ locale ][$ key ] = $ value ;
119
117
}
120
118
121
-
122
119
/**
123
120
* @param $key
124
121
* @param $locale
122
+ *
125
123
* @return string|null
126
124
*/
127
125
public function getTranslation ($ key , $ locale = null )
@@ -163,6 +161,7 @@ public function unsetTranslation($locale, $key = null)
163
161
/**
164
162
* @param $key
165
163
* @param $value
164
+ *
166
165
* @return $this
167
166
*/
168
167
public function setAttribute ($ key , $ value )
@@ -176,7 +175,6 @@ public function setAttribute($key, $value)
176
175
return parent ::setAttribute ($ key , $ value );
177
176
}
178
177
179
-
180
178
/**
181
179
* Load transaltions from database.
182
180
*/
@@ -218,7 +216,7 @@ public function getAvailableLocales()
218
216
*/
219
217
public function getDefaultLocale ()
220
218
{
221
- return config ('app.locale ' );
219
+ return config ('app.fallback_locale ' );
222
220
}
223
221
224
222
/**
@@ -271,16 +269,14 @@ public function getTranslationModel()
271
269
272
270
/**
273
271
* @param $key
272
+ *
274
273
* @return bool
275
274
*/
276
275
public function isTranslatable ($ key )
277
276
{
278
277
return in_array ($ key , $ this ->translatable );
279
278
}
280
279
281
- /**
282
- *
283
- */
284
280
public function refreshTranslations ()
285
281
{
286
282
$ this ->translatedAttributes = [];
@@ -295,4 +291,4 @@ public function getTranslatable()
295
291
{
296
292
return $ this ->translatable ;
297
293
}
298
- }
294
+ }
0 commit comments