Add API
This commit is contained in:
49
app/Models/Person.php
Normal file
49
app/Models/Person.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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 = [
|
||||
'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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user