simedkom/app/Models/ContentRecap.php
Alfin Afif 15b1e8af19 All In
2025-07-30 08:46:00 +07:00

72 lines
1.8 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 ContentRecap extends Model
{
use SoftDeletes, LogsActivity;
protected $table = 'content_recaps';
protected $fillable = [
'content_theme',
'posted_date',
'channel',
'link',
'classification_id',
'social_media',
'image',
'content_type',
'description',
'enhancer_id',
];
public function enhancer()
{
return $this->belongsTo(User::class, 'enhancer_id', 'id');
}
public function classification(){
return $this->belongsTo(ContentRecapClassification::class, 'classification_id', 'id');
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly([
'content_theme',
'posted_date',
'channel',
'link',
'classification_id',
'social_media',
'image',
'content_type',
'description',
'enhancer_id',]) // kolom yang dicatat
->useLogName('content_recap') // 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 "Rekap Konten '{$this->content_theme}' telah {$eventName}";
}
}