feat: anggota dapat menulis artikel dengan workflow approval sebelum diterbitkan
This commit is contained in:
+10
-2
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user