*/ use HasFactory, HasUuids; protected $fillable = [ 'workspace_id', 'user_id', 'status', 'synced', 'scheduled_at', 'published_at', ]; protected function casts(): array { return [ 'status' => PostStatus::class, 'synced' => 'boolean', 'scheduled_at' => 'datetime', 'published_at' => 'datetime', ]; } public function workspace(): BelongsTo { return $this->belongsTo(Workspace::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function postPlatforms(): HasMany { return $this->hasMany(PostPlatform::class); } public function scopeScheduled(Builder $query): Builder { return $query->where('status', PostStatus::Scheduled); } public function scopeDue(Builder $query): Builder { return $query->scheduled()->where('scheduled_at', '<=', now()); } public function scopeDraft(Builder $query): Builder { return $query->where('status', PostStatus::Draft); } public function scopePublished(Builder $query): Builder { return $query->where('status', PostStatus::Published); } public function scopeFailed(Builder $query): Builder { return $query->where('status', PostStatus::Failed); } public function markAsPublishing(): void { $this->update(['status' => PostStatus::Publishing]); } public function markAsPublished(): void { $this->update([ 'status' => PostStatus::Published, 'published_at' => now(), ]); } public function markAsPartiallyPublished(): void { $this->update([ 'status' => PostStatus::PartiallyPublished, 'published_at' => now(), ]); } public function markAsFailed(): void { $this->update(['status' => PostStatus::Failed]); } }