61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
class GovernmentAgency extends Model
|
|
{
|
|
use LogsActivity, SoftDeletes;
|
|
|
|
protected $table = 'government_agencies';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'short_name',
|
|
'location',
|
|
'description',
|
|
'enhancer_id',
|
|
];
|
|
|
|
public function issues()
|
|
{
|
|
return $this->belongsToMany(IssueManagement::class, 'issue_managements_government_agencies', 'government_agency_id', 'issue_management_id')
|
|
->using(IssueManagementGovernmentAgency::class)
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function enhancer()
|
|
{
|
|
return $this->belongsTo(User::class, 'enhancer_id', 'id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['name', 'short_name', 'location', 'description', 'enhancer_id']) // kolom yang dicatat
|
|
->useLogName('government_agency') // nama log
|
|
->logOnlyDirty(); // hanya log kalau ada perubahan
|
|
}
|
|
|
|
public function getDescriptionForEvent(string $eventName): string
|
|
{
|
|
switch ($eventName) {
|
|
case 'created':
|
|
$eventName = 'dibuat';
|
|
break;
|
|
case 'updated':
|
|
$eventName = 'diubah';
|
|
break;
|
|
case 'deleted':
|
|
$eventName = 'dihapus';
|
|
break;
|
|
}
|
|
|
|
return "OPD '{$this->name}' telah {$eventName}";
|
|
}
|
|
}
|