generated from liutk/owl-admin-base
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
class Person extends Model
|
|
{
|
|
use HasFactory;
|
|
use Filterable;
|
|
|
|
protected $table = 'persons';
|
|
|
|
protected $fillable = ['type','name', 'used_name', 'value', 'parent_id', 'parent_key', 'path', 'sort', 'lv', 'oid'];
|
|
|
|
protected $appends = ['age', 'now_address'];
|
|
|
|
protected function serializeDate(\DateTimeInterface $date)
|
|
{
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
$q->orderBy('id', 'asc');
|
|
}
|
|
|
|
//户主
|
|
public function master()
|
|
{
|
|
return $this->belongsTo(static::class, 'master_id');
|
|
}
|
|
|
|
//年龄
|
|
protected function age():Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => $this->birthday ? Carbon::parse($this->birthday)->diffInYears(now()).'岁' : "未知",
|
|
);
|
|
}
|
|
|
|
protected function nowAddress(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => $this->house_complete_address ? : $this->real_address,
|
|
);
|
|
}
|
|
}
|