1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use App\Traits\Events; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use LaravelEnso\AddressesManager\app\Traits\Addressable; |
8
|
|
|
use LaravelEnso\CommentsManager\app\Traits\Commentable; |
9
|
|
|
use LaravelEnso\Contacts\app\Traits\Contactable; |
10
|
|
|
use LaravelEnso\DocumentsManager\app\Traits\Documentable; |
11
|
|
|
use Ramsey\Uuid\Uuid; |
12
|
|
|
|
13
|
|
|
class Individual extends Model |
14
|
|
|
{ |
15
|
|
|
use Contactable, Commentable, Documentable, Addressable, Events; |
16
|
|
|
|
17
|
|
|
protected $appends = ['name']; |
18
|
|
|
|
19
|
|
|
protected $fillable = ['first_name', 'last_name', 'is_active', 'gender', 'type_id']; |
20
|
|
|
|
21
|
|
|
protected $attributes = ['is_active' => false]; |
22
|
|
|
|
23
|
|
|
protected $casts = ['is_active' => 'boolean']; |
24
|
|
|
|
25
|
|
|
public static function boot() |
26
|
|
|
{ |
27
|
|
|
parent::boot(); |
28
|
|
|
|
29
|
|
|
static::creating(function ($model) { |
30
|
|
|
$model->uuid = (string) Uuid::uuid4(); |
31
|
|
|
}); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public function families() |
36
|
|
|
{ |
37
|
|
|
return $this->belongsToMany(Family::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function children() |
41
|
|
|
{ |
42
|
|
|
return $this->belongsToMany(self::class, 'child_parent', 'child_id', 'parent_id'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function parents() |
46
|
|
|
{ |
47
|
|
|
return $this->belongsToMany(self::class, 'child_parent', 'parent_id', 'child_id'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getNameAttribute() |
51
|
|
|
{ |
52
|
|
|
return "{$this->first_name} {$this->last_name}"; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|