pawelmysior/laravel-publishable
published_at timestamp). This is a clean, database-efficient approach for content moderation, A/B testing, or staged releases.published(), unpublished()), reducing boilerplate and improving readability. Complements existing Laravel features like whereNotNull() or whereDate().published_at column).$fillable (only for v1.x).published_at to existing tables may require downtime or migration strategies (e.g., zero-downtime alters in production).WHERE clause, but impact is negligible unless filtering large datasets without indexes. Ensure published_at is indexed:
$table->timestamp('published_at')->nullable()->index();
published_at uses UTC by default (Laravel’s behavior). Clarify if application uses non-UTC timestamps.null as unpublished; future dates may need custom logic (e.g., scheduled() scope).deleted_at)? If so, consider consistency (e.g., unified trait for both).is_published)? Migration strategy needed.published() with other scopes (e.g., Post::published()->where('category', 'news'))? Test performance.published_by).published_at or use factory seeds?published_at (prioritize high-traffic models first).published_at column with index:
Schema::table('posts', function (Blueprint $table) {
$table->timestamp('published_at')->nullable()->index()->after('updated_at');
});
addColumn with nullable first).Publishable trait to models:
use PawelMysior\Publishable\Publishable;
class Post extends Model { use Publishable; }
is_published boolean fields) or deprecate gradually.published_at:
Post::where('is_published', true)->update(['published_at' => now()]);
Post::published()->count(); // Should match expected published records.
Post::unpublished()->count();
null, future dates, timezone consistency.SoftDeletes, ActsAsTenant). No known conflicts, but test.Post::query().scheduled()), ensure they integrate with existing scopes:
class Post extends Model {
use Publishable;
public function scopeScheduled($query) {
return $query->where('published_at', '>', now());
}
}
recentlyPublished()).pawelmysior/laravel-publishable from v3.x to v4.x.published_at to new tables by default.published_at to migrations.published_at stored in UTC but app uses EST).Post::published()->where(...) failing).published_at.published_at to avoid full-table scans:
CREATE INDEX idx_posts_published_at ON posts(published_at);
published_at is a timestamp; ensure it’s included in sharding keys if partitioning by date ranges.| Failure Scenario | Impact | Mitigation |
|---|---|---|
Migration fails (e.g., published_at conflict) |
Downtime if blocking migration. | Use non-blocking migrations; test in staging. |
published_at not indexed |
Slow queries on large tables. | Add index in migration; monitor query plans. |
| Timezone misconfiguration | Incorrect publishing states. | Enforce UTC in migrations; test with Carbon::parse(). |
| Legacy boolean flag not migrated | Inconsistent publishing states. | Backfill data; add validation to prevent duplicates. |
| Package abandoned | No updates for new Laravel versions. | Fork or evaluate alternatives (e.g., Spatie’s Publishable). |
| Overuse of scopes | Complex, unreadable queries. | Enforce query complexity limits; document scope usage guidelines. |
How can I help you explore Laravel packages today?