Passed
Push — master ( ff9c9e...a4cc29 )
by Robin
02:37
created

VocabTerm::cites()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
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(config('trans-helper.database.table.term'));
21
        parent::__construct($attributes);
22
    }
23
24
    public function cites()
25
    {
26
        return $this->belongsToMany(
27
            config('trans-helper.model.cite'),
28
            config('trans-helper.database.table.link'),
29
            'vocab',
30
            'cited',
31
            'id',
32
            'id'
33
        );
34
    }
35
36
    public function sweep()
37
    {
38
        if ($this->cites()->count() < 1) {
39
            $this->delete();
40
        }
41
    }
42
}
43