robinhoo1973 /
laravel-translation-helper
| 1 | <?php |
||
| 2 | |||
| 3 | namespace TopviewDigital\TranslationHelper\Model; |
||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Model; |
||
| 6 | |||
| 7 | class VocabTerm extends Model |
||
| 8 | { |
||
| 9 | protected $casts = [ |
||
| 10 | 'translation' => 'json', |
||
| 11 | ]; |
||
| 12 | protected $fillable = [ |
||
| 13 | 'term', 'translation', 'namespace', |
||
| 14 | ]; |
||
| 15 | |||
| 16 | public function __construct(array $attributes = []) |
||
| 17 | { |
||
| 18 | $connection = config('trans-helper.database.connection') ?: config('database.default'); |
||
| 19 | $this->setConnection($connection); |
||
| 20 | $this->setTable('_trans_helper_terms'); |
||
| 21 | parent::__construct($attributes); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function cites() |
||
| 25 | { |
||
| 26 | return $this->belongsToMany( |
||
| 27 | VocabCite::class, |
||
| 28 | '_trans_helper_links', |
||
| 29 | 'vocab', |
||
| 30 | 'cited', |
||
| 31 | 'id', |
||
| 32 | 'id' |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function getSlugAttribute($attr) |
||
|
0 ignored issues
–
show
|
|||
| 37 | { |
||
| 38 | $key = slugify($this->translation['en']); |
||
|
0 ignored issues
–
show
|
|||
| 39 | |||
| 40 | return $key; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function sweep() |
||
| 44 | { |
||
| 45 | if ($this->cites()->count() < 1) { |
||
| 46 | $this->delete(); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | public static function namespaces() |
||
| 51 | { |
||
| 52 | return self::distinct('namespace')->pluck('namespace')->toArray(); |
||
| 53 | } |
||
| 54 | |||
| 55 | public static function locales() |
||
| 56 | { |
||
| 57 | return array_unique( |
||
| 58 | call_user_func_array( |
||
| 59 | 'array_merge', |
||
| 60 | array_map( |
||
| 61 | function ($u) { |
||
| 62 | return array_keys($u->translation); |
||
| 63 | }, |
||
| 64 | self::get()->all() |
||
| 65 | ) |
||
| 66 | ) |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.