Passed
Push — master ( 92bcbd...28ff2f )
by Curtis
06:11
created

Family   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndividualListAttribute() 0 5 1
A individuals() 0 3 1
A info() 0 2 1
A spouse() 0 2 1
1
<?php
2
3
namespace App;
4
5
use App\Traits\Events;
6
use App\Traits\HasIndividuals;
7
use Illuminate\Database\Eloquent\Model;
8
use LaravelEnso\AddressesManager\app\Traits\Addressable;
9
use LaravelEnso\CommentsManager\app\Traits\Commentable;
10
use LaravelEnso\DocumentsManager\app\Traits\Documentable;
11
12
class Family extends Model
13
{
14
    use Commentable, Documentable, Addressable, HasIndividuals, Events;
15
16
    protected $fillable = ['description', 'is_active', 'father_id', 'mother_id', 'type_id'];
17
18
    protected $attributes = ['is_active' => false];
19
20
    protected $casts = ['is_active' => 'boolean'];
21
22
    public function individuals()
23
    {
24
        return $this->belongsToMany(Individual::class)->withPivot('type_id');
25
    }
26
27
    public function getIndividualListAttribute()
28
    {
29
        return $this->individuals()->where('individuals.id', '!=', $this->father_id)
30
            ->where('individuals.id', '!=', $this->mother_id)
31
            ->pluck('individuals.id');
32
    }
33
34
    public function info(){
35
        return $this->belongsTo(Individual::class,'father_id','id');
36
    }
37
38
    public function spouse(){
39
        return $this->hasOne(Individual::class,'id','mother_id');
40
    }
41
}
42