73 lines
1.7 KiB
PHP
73 lines
1.7 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 Report extends Model
|
|
{
|
|
use LogsActivity, SoftDeletes;
|
|
|
|
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}";
|
|
}
|
|
}
|