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
|
|
|
|
|
{
|
2026-04-06 00:27:32 +07:00
|
|
|
if ($post->wasChanged('status') && $post->status === 'published') {
|
2026-04-05 06:21:16 +07:00
|
|
|
MemberPoint::firstOrCreate(
|
|
|
|
|
[
|
|
|
|
|
'user_id' => $post->author_id,
|
|
|
|
|
'source_type' => Post::class,
|
|
|
|
|
'source_id' => $post->id,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'points' => 5,
|
|
|
|
|
'reason' => "Artikel disetujui: {$post->title}",
|
|
|
|
|
]
|
|
|
|
|
);
|
2026-04-04 06:44:54 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|