Update Spatie versi 4
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
||||
use Spatie\Activitylog\Support\LogOptions;
|
||||
use Spatie\Activitylog\Contracts\Activity;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
trait CatatAktivitas
|
||||
{
|
||||
@@ -36,15 +36,19 @@ trait CatatAktivitas
|
||||
->logExcept([...self::$kolomTidakDicatat, ...$this->getHidden()])
|
||||
->dontLogIfAttributesChangedOnly(self::$kolomTidakDicatat)
|
||||
->logOnlyDirty()
|
||||
->dontLogEmptyChanges()
|
||||
->dontSubmitEmptyLogs()
|
||||
->setDescriptionForEvent(fn (string $event) => $label . ' ' . (self::$kataEvent[$event] ?? $event));
|
||||
}
|
||||
|
||||
// Tandai petani terkait
|
||||
public function beforeActivityLogged(Model $activity, string $event): void
|
||||
// Simpan nama data & petani terkait di log (halaman log tak perlu memuat data asli)
|
||||
public function tapActivity(Activity $activity, string $eventName): void
|
||||
{
|
||||
if ($petaniId = $this->getAttribute('petani_id')) {
|
||||
$activity->properties = $activity->properties->put('petani_id', (int) $petaniId);
|
||||
}
|
||||
$label = $this->getAttribute('nama') ?? $this->getAttribute('name');
|
||||
$petaniId = $this->getAttribute('petani_id');
|
||||
|
||||
$activity->properties = $activity->properties->merge(array_filter([
|
||||
'label' => is_string($label) ? Str::limit($label, 100) : null,
|
||||
'petani_id' => $petaniId ? (int) $petaniId : null,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user