75 lines
1.9 KiB
PHP
75 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 Cooperation extends Model
|
|
{
|
|
use SoftDeletes, LogsActivity;
|
|
|
|
protected $table = 'cooperations';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'start_date',
|
|
'end_date',
|
|
'banner',
|
|
'offer_file_template',
|
|
'description',
|
|
'enhancer_id',
|
|
];
|
|
|
|
public function media()
|
|
{
|
|
return $this->belongsToMany(Media::class, 'media_cooperations', 'cooperation_id', 'media_id')
|
|
->using(MediaCooperation::class)
|
|
->withPivot(['status', 'rejection_reason'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function proposals(){
|
|
return $this->hasMany(CooperationProposal::class, 'cooperation_id', 'id');
|
|
}
|
|
|
|
public function mediaOrder(){
|
|
return $this->hasOne(Order::class, 'cooperation_id', 'id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly([
|
|
'name',
|
|
'start_date',
|
|
'end_date',
|
|
'banner',
|
|
'offer_file_template',
|
|
'description',
|
|
'enhancer_id',
|
|
]) // kolom yang dicatat
|
|
->useLogName('cooperation') // 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 "Kerja Sama '{$this->name}' telah {$eventName}";
|
|
}
|
|
}
|