forceFill(match (true) { $record instanceof Page => ['status' => PageStatus::Published, 'published_at' => $at], $record instanceof Project => ['published_at' => $at], $record instanceof Service => ['is_published' => true, 'published_at' => $at], default => throw new InvalidArgumentException($record::class.' is not published this way.'), })->save(); // Publishing now closes the review by itself (HasReviews); a date in // the future does not, so it is closed here. if ($record->isAwaitingReview()) { $record->closeReview(); } } public static function unpublish(Model $record): void { $record->forceFill(match (true) { $record instanceof Page => ['status' => PageStatus::Draft], $record instanceof Project => ['published_at' => null], $record instanceof Service => ['is_published' => false], default => throw new InvalidArgumentException($record::class.' is not published this way.'), })->save(); } }