74 lines
1.9 KiB
PHP
74 lines
1.9 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 CooperationProposal extends Model
|
|
{
|
|
use LogsActivity;
|
|
|
|
protected $table = 'cooperation_proposals';
|
|
|
|
protected $fillable = [
|
|
'attachment',
|
|
'status',
|
|
'e_catalog',
|
|
'description',
|
|
'rejection_reason',
|
|
'cooperation_id',
|
|
'media_id',
|
|
];
|
|
|
|
public function media(){
|
|
return $this->belongsTo(Media::class, 'media_id', 'id');
|
|
}
|
|
|
|
public function cooperation(){
|
|
return $this->belongsTo(Cooperation::class, 'cooperation_id', 'id');
|
|
}
|
|
|
|
public function journalists()
|
|
{
|
|
return $this->belongsToMany(Journalist::class, 'journalists_cooperation_proposals', 'cooperation_proposal_id', 'journalist_id')
|
|
->using(JournalistCooperationProposal::class)
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly([
|
|
'attachment',
|
|
'status',
|
|
'e_catalog',
|
|
'description',
|
|
'rejection_reason',
|
|
'cooperation_id',
|
|
'media_id',
|
|
])
|
|
->useLogName('cooperation_proposal') // 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 "Pengajuan kerja sama telah {$eventName}";
|
|
}
|
|
}
|