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

Family::individuals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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