96 lines
2.3 KiB
PHP
96 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Laravel\Scout\Searchable;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
use Spatie\Activitylog\LogOptions;
|
|
|
|
class Person extends Model
|
|
{
|
|
use HasFactory, SoftDeletes, LogsActivity;
|
|
|
|
protected $table = 'person';
|
|
protected $primaryKey = 'person_id';
|
|
|
|
protected $fillable = [
|
|
'surname',
|
|
'christian_name',
|
|
'full_name',
|
|
'date_of_birth',
|
|
'place_of_birth',
|
|
'date_of_death',
|
|
'occupation',
|
|
'additional_notes',
|
|
'reference',
|
|
'id_card_no',
|
|
];
|
|
|
|
protected $casts = [
|
|
'date_of_birth' => 'date',
|
|
'date_of_death' => 'date',
|
|
];
|
|
|
|
// 🔧 Configure Spatie logging
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->useLogName('person')
|
|
->logFillable()
|
|
->logOnlyDirty();
|
|
}
|
|
|
|
// 📝 Custom activity description for events
|
|
public function getDescriptionForEvent(string $eventName): string
|
|
{
|
|
return match ($eventName) {
|
|
'created' => 'Added new migrant',
|
|
'updated' => 'Updated migrant details',
|
|
'deleted' => 'Deleted migrant record',
|
|
default => ucfirst($eventName) . ' migrant record',
|
|
};
|
|
}
|
|
|
|
// 🔗 Relationships
|
|
public function migration()
|
|
{
|
|
return $this->hasOne(Migration::class, 'person_id');
|
|
}
|
|
|
|
public function naturalization()
|
|
{
|
|
return $this->hasOne(Naturalization::class, 'person_id');
|
|
}
|
|
|
|
public function residence()
|
|
{
|
|
return $this->hasOne(Residence::class, 'person_id');
|
|
}
|
|
|
|
public function family()
|
|
{
|
|
return $this->hasOne(Family::class, 'person_id');
|
|
}
|
|
|
|
public function internment()
|
|
{
|
|
return $this->hasOne(Internment::class, 'person_id');
|
|
}
|
|
|
|
public function photos()
|
|
{
|
|
return $this->hasMany(Photo::class, 'person_id', 'person_id');
|
|
}
|
|
|
|
public function profilePhoto()
|
|
{
|
|
return $this->hasMany(Photo::class, 'person_id', 'person_id')
|
|
->where('is_profile_photo', true)
|
|
->latest()
|
|
->first();
|
|
}
|
|
}
|