Passed
Pull Request — master (#1309)
by Curtis
05:59
created

Tag   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 7 2
A videos() 0 7 1
1
<?php
2
3
namespace App\Models\enso\howto;
4
5
use Illuminate\Database\Eloquent\Model;
6
use LaravelEnso\HowTo\Exceptions\Tag as Exception;
7
8
class Tag extends Model
9
{
10
    protected $table = 'how_to_tags';
11
12
    protected $guarded = ['id'];
13
14
    public function videos()
15
    {
16
        return $this->belongsToMany(
17
            Video::class,
18
            'how_to_tag_how_to_video',
19
            'how_to_tag_id',
20
            'how_to_video_id'
21
        );
22
    }
23
24
    public function delete()
25
    {
26
        if ($this->videos()->exists()) {
27
            throw Exception::inUse();
28
        }
29
30
        parent::delete();
31
    }
32
}
33