27 lines
634 B
PHP
27 lines
634 B
PHP
<?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 === 'approved') {
|
|
MemberPoint::firstOrCreate(
|
|
[
|
|
'user_id' => $post->author_id,
|
|
'source_type' => Post::class,
|
|
'source_id' => $post->id,
|
|
],
|
|
[
|
|
'points' => 5,
|
|
'reason' => "Artikel disetujui: {$post->title}",
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|