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\Traits\LogsActivity;
|
|
use Spatie\Activitylog\LogOptions;
|
|
|
|
class SubClassification extends Model
|
|
{
|
|
use SoftDeletes, LogsActivity;
|
|
|
|
protected $table = 'sub_classifications';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'status',
|
|
'description',
|
|
'classification_id',
|
|
'enhancer_id'
|
|
];
|
|
|
|
public function classification(){
|
|
return $this->belongsTo(Classification::class, 'classification_id', 'id')->withTrashed();
|
|
}
|
|
|
|
public function issues(){
|
|
return $this->hasMany(IssueManagement::class, 'sub_classification_id', 'id');
|
|
}
|
|
|
|
public function enhancer(){
|
|
return $this->belongsTo(User::class, 'enhancer_id', 'id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly([ 'name', 'status', 'description', 'classification_id', 'enhancer_id']) // kolom yang dicatat
|
|
->useLogName('sub_classification') // 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 "Sub Klasifikasi '{$this->name}' telah {$eventName}";
|
|
}
|
|
}
|