feat: anggota dapat menulis artikel dengan workflow approval sebelum diterbitkan

This commit is contained in:
2026-04-03 06:48:06 +07:00
parent 5d14b55173
commit a7e10600d4
12 changed files with 339 additions and 10 deletions
+10 -2
View File
@@ -8,7 +8,7 @@ use Illuminate\Support\Str;
class Post extends Model
{
protected $fillable = ['title', 'slug', 'category', 'content', 'author_id', 'published_at'];
protected $fillable = ['title', 'slug', 'category', 'content', 'author_id', 'published_at', 'status', 'reviewed_by', 'rejection_reason'];
protected $casts = ['published_at' => 'datetime'];
@@ -16,6 +16,7 @@ class Post extends Model
{
static::creating(function (Post $post) {
$post->slug ??= Str::slug($post->title);
$post->author_id ??= auth()->id();
});
}
@@ -24,8 +25,15 @@ class Post extends Model
return $this->belongsTo(User::class, 'author_id');
}
public function reviewer(): BelongsTo
{
return $this->belongsTo(User::class, 'reviewed_by');
}
public function scopePublished($query)
{
return $query->whereNotNull('published_at')->where('published_at', '<=', now());
return $query->where('status', 'published')
->whereNotNull('published_at')
->where('published_at', '<=', now());
}
}