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

71 lines
1.7 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 Report extends Model
{
use SoftDeletes, LogsActivity;
protected $table = 'reports';
protected $fillable = [
'title',
'publication_date',
'link',
'proof',
'description',
'status',
'rejection_reason',
'media_id',
'order_id',
];
public function order(){
return $this->belongsTo(Order::class, 'order_id', 'id');
}
public function media(){
return $this->belongsTo(Media::class, 'media_id', 'id');
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly([
'title',
'publication_date',
'link',
'proof',
'description',
'status',
'rejection_reason',
'media_id',
'order_id',
]) // kolom yang dicatat
->useLogName('airing_proof_report') // 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 "Penyelesaian kerja sama '{$this->title}' telah {$eventName}";
}
}