91 lines
2.3 KiB
PHP
91 lines
2.3 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',
|
|
'main_address_id',
|
|
'domicile_address_id',
|
|
];
|
|
|
|
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 currentAddress()
|
|
{
|
|
return $this->belongsTo(Address::class, 'main_address_id');
|
|
}
|
|
|
|
public function domicileAddress()
|
|
{
|
|
return $this->belongsTo(Address::class, 'main_address_id');
|
|
}
|
|
|
|
public function metas()
|
|
{
|
|
return $this->morphMany(Meta::class, 'metaable');
|
|
}
|
|
|
|
public function owner()
|
|
{
|
|
return $this->belongsTo(User::class, 'owner_user_id');
|
|
}
|
|
|
|
public function makeLmsApiData()
|
|
{
|
|
return [
|
|
'name' => $this->name,
|
|
'birth_date' => $this->birth_date,
|
|
'birth_place' => $this->birth_place,
|
|
'gender' => $this->gender,
|
|
'blood_type' => $this->blood_type,
|
|
'religion' => $this->religion,
|
|
'last_education' => $this->last_education,
|
|
'current_employment' => $this->current_employment,
|
|
'marital_status' => $this->marital_status,
|
|
'nik' => $this->nik,
|
|
'citizenship' => $this->citizenship,
|
|
'address' => $this->currentAddress->text ?? null,
|
|
'city_name' => $this->currentAddress->city->name ?? null,
|
|
'domicile_address' => $this->domicileAddress->text ?? null,
|
|
'domicile_city_name' => $this->domicileAddress->city->name ?? null,
|
|
'email' => $this->email,
|
|
'phone' => $this->phone,
|
|
];
|
|
}
|
|
}
|