59 lines
1.5 KiB
PHP
59 lines
1.5 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 ContentRecapClassification extends Model
|
|
{
|
|
use LogsActivity, SoftDeletes;
|
|
|
|
protected $table = 'content_recap_classifications';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'slug',
|
|
'year',
|
|
'description',
|
|
'enhancer_id',
|
|
];
|
|
|
|
public function contentRecaps()
|
|
{
|
|
return $this->hasMany(ContentRecap::class, 'classification_id', 'id');
|
|
}
|
|
|
|
public function enhancer()
|
|
{
|
|
return $this->belongsTo(User::class, 'enhancer_id', 'id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['name', 'slug', 'year', 'description', 'enhancer_id']) // kolom yang dicatat
|
|
->useLogName('content_recap_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 "Klasifikasi Rekap Konten '{$this->name}' telah {$eventName}";
|
|
}
|
|
}
|