-
Notifications
You must be signed in to change notification settings - Fork 554
/
IsTranslatable.php
40 lines (34 loc) · 1.12 KB
/
IsTranslatable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace A17\Twill\Models\Behaviors;
trait IsTranslatable
{
/**
* @param array
*/
public $translatedAttributes = [];
/**
* Checks if this model is translatable.
*
* If no columns/column is provided it will return true if the model itself is translatable.
*/
public function isTranslatable(null|array|string $columns = null): bool
{
// Model must have the trait
if (! classHasTrait($this, \A17\Twill\Models\Behaviors\HasTranslation::class)) {
return false;
}
// Model must have the translatedAttributes property
if (! property_exists($this, 'translatedAttributes')) {
return false;
}
// If it's a check on certain columns
// They must be present in the translatedAttributes
if (filled($columns)) {
return collect($this->getTranslatedAttributes())
->intersect(collect($columns))
->isNotEmpty();
}
// The translatedAttributes property must be filled
return collect($this->getTranslatedAttributes())->isNotEmpty();
}
}