2026-04-04 06:44:54 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
|
|
|
|
|
use App\Models\MemberPoint;
|
|
|
|
|
use App\Models\Post;
|
|
|
|
|
|
|
|
|
|
class PostObserver
|
|
|
|
|
{
|
|
|
|
|
public function updated(Post $post): void
|
|
|
|
|
{
|
|
|
|
|
if ($post->wasChanged('status') && $post->status === 'published') {
|
|
|
|
|
MemberPoint::create([
|
2026-04-04 08:25:27 +07:00
|
|
|
'user_id' => $post->author_id,
|
2026-04-04 06:44:54 +07:00
|
|
|
'points' => 5,
|
|
|
|
|
'reason' => "Artikel dipublikasi: {$post->title}",
|
|
|
|
|
'source_type' => 'post',
|
|
|
|
|
'source_id' => $post->id,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|