62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
class Announcement extends Model
|
|
{
|
|
use LogsActivity;
|
|
|
|
protected $table = 'announcements';
|
|
|
|
protected $fillable = [
|
|
'headline',
|
|
'content',
|
|
'link',
|
|
'attachment',
|
|
'enhancer_id',
|
|
];
|
|
|
|
public function enhancer()
|
|
{
|
|
return $this->belongsTo(User::class, 'enhancer_id', 'id');
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
return $this->belongsToMany(User::class, 'announcements_users', 'announcement_id', 'user_id')
|
|
->using(AnnouncementUser::class)
|
|
->withPivot(['status', 'category'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['headline', 'content', 'link', 'attachment', 'enhancer_id']) // kolom yang dicatat
|
|
->useLogName('announcement') // 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 "Pengumuman pengguna '{$this->headline}' telah {$eventName}";
|
|
|
|
}
|
|
}
|