Files
aso/app/Models/Person.php
2022-09-20 09:31:26 +07:00

56 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
use HasFactory;
protected $table = 'persons';
protected $fillable = [
'owner_user_id',
'nik',
'name_prefix',
'name',
'name_suffix',
'gender',
'birth_date',
'is_deceased',
'deceased_at',
'marital_status',
];
public function getFullNameAttribute()
{
$arr = [];
if (!empty($this->name_prefix)) {
$arr[] = $this->name_prefix;
}
$arr[] = $this->name;
if (!empty($this->name_suffix)) {
$arr[] = $this->name_suffix;
}
return implode(' ', $arr);
}
public function addresses()
{
return $this->morphMany(Address::class, 'addressable');
}
public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
}
public function owner()
{
return $this->belongsTo(User::class, 'owner_user_id');
}
}