Completed
Push — master ( 5b54fc...16c96d )
by Bertrand
14:42
created

CharacteristicsModel::users()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
4
namespace App\Src\UseCases\Infra\Sql\Model;
5
6
7
use App\Src\UseCases\Domain\Agricultural\Dto\CharacteristicDto;
8
use App\User;
9
use Illuminate\Database\Eloquent\Model;
10
11
class CharacteristicsModel extends Model
12
{
13
    protected $table = 'characteristics';
14
15
    protected $fillable = [
16
        'uuid',
17
        'main',
18
        'priority',
19
        'icon',
20
        'page_label',
21
        'pretty_page_label',
22
        'page_id',
23
        'type',
24
        'code',
25
    ];
26
27
    public function users()
28
    {
29
        return $this->belongsToMany(User::class)
30
            ->using(UserCharacteristicsModel::class);
31
    }
32
33
    public function toDto()
34
    {
35
        $icon = null;
36
        if(isset($this->icon)){
37
            $icon = route('api.icon.serve', ['id' => $this->uuid]);
38
        }
39
        return new CharacteristicDto(
40
            $this->uuid,
41
            $this->page_label,
42
            $this->type,
43
            $icon,
44
            $this->pretty_page_label
45
        );
46
    }
47
}
48