Files
persegi/app/Observers/PostObserver.php
T

23 lines
544 B
PHP
Raw Normal View History

<?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([
'user_id' => $post->author_id,
'points' => 5,
'reason' => "Artikel dipublikasi: {$post->title}",
'source_type' => 'post',
'source_id' => $post->id,
]);
}
}
}