- How do I add publishing support to an existing Laravel Eloquent model?
- Use the `Publishes` trait in your model class and update its migration with `$table->publishes()` to add the `published_at` column. No additional configuration is needed for basic functionality. For custom column names, use `$table->publishes('custom_column_name')`.
- Does this package work with Laravel 10+ and PHP 8.2+?
- Yes, the package officially supports Laravel 9+ and PHP 8.1+, with active development for Laravel 13 and PHP 8.5. Check the [GitHub releases](https://github.com/leMaur/eloquent-publishing/releases) for version-specific compatibility notes.
- Can I query only published or unpublished records easily?
- Absolutely. The package provides built-in query scopes like `onlyPublished()`, `onlyUnpublished()`, and `latestPlanned()` for filtering. These integrate seamlessly with Eloquent’s query builder for fluent syntax.
- What happens if I need timezone-aware publish dates?
- By default, timestamps use UTC. For timezone-aware dates, use the `publishesTz()` migration method or manually set the column’s timezone in your model. The trait itself doesn’t enforce timezones but supports custom column logic.
- How do I trigger actions when a model is published or unpublished?
- The package dispatches events like `Publishing`, `Published`, `Unpublishing`, and `Unpublished`. Listen to these events in your `EventServiceProvider` or via Laravel’s event system to add custom logic like notifications or auditing.
- Is there a way to bulk-publish or unpublish multiple records?
- Yes, you can use Eloquent’s `update()` or `each()` methods to batch-update `published_at` values. For performance, ensure your `published_at` column is indexed. The package doesn’t include bulk operations natively but works with standard Eloquent patterns.
- Can I combine this with soft deletes or versioning?
- The package focuses solely on publishing workflows and doesn’t include soft deletes or versioning. However, you can use it alongside Laravel’s `SoftDeletes` trait or third-party versioning packages like `spatie/laravel-activitylog` without conflicts.
- What if I need to add the `published_at` column to an existing production database?
- Run a new migration with `$table->timestamp('published_at')->nullable()->after('created_at')` and backfill existing records with a seeder or data update script. The package won’t alter existing data—it only adds the column for new records.
- Are there any performance considerations for large datasets?
- The package adds minimal overhead. Query scopes use standard Eloquent optimizations, but for large datasets, ensure the `published_at` column is indexed. Avoid complex joins in scopes if performance is critical.
- What alternatives exist for Laravel model publishing?
- Alternatives include `spatie/laravel-activitylog` (for auditing), `laravel-nova` (for admin panels with publishing), or custom solutions using Eloquent accessors. However, this package is lightweight and tailored specifically for publish/unpublish workflows with zero external dependencies.