- How do I enable drafts for an Eloquent model in Laravel?
- Use the `HasDrafts` trait on your model and run the migration to add the required columns (`is_current`, `is_published`, etc.). The package handles the rest, including relation syncing. No need for custom logic unless you need advanced customization.
- Can I use Laravel Drafts with Laravel Nova for content management?
- Yes, the package integrates seamlessly with Laravel Nova. You can display drafts, revisions, and preview unpublished content directly in Nova’s admin interface. The `WithDraftsMiddleware` helps restrict access to drafts in development or staging.
- What Laravel versions does oddvalue/laravel-drafts support?
- The package supports Laravel 9 through 13, ensuring compatibility with the latest LTS releases. It follows Laravel’s conventions, so updates are typically smooth unless you’ve heavily customized the package’s behavior.
- How does the preview mode work, and can I restrict access?
- Preview mode loads the latest draft instead of the published record. You can secure it using Laravel’s built-in middleware (e.g., `auth`, `ip`, or custom middleware) to ensure only authorized users can access drafts before publishing.
- Does Laravel Drafts handle relations between models automatically?
- Yes, it automatically syncs `HasOne`, `HasMany`, `BelongsToMany`, and `MorphToMany` relations between drafts and published records. For complex or polymorphic relations, you may need to override `getDraftableRelations()` in your model.
- What happens if I delete a published record? Will revisions be orphaned?
- Revisions are soft-deleted by default, so they won’t be immediately removed. However, if you hard-delete a published record, revisions may linger. You’ll need to manually clean them up or configure a custom cleanup process.
- Can I customize the number of revisions retained per model?
- Yes, the default retention is 10 revisions, but you can adjust this in the config file (`drafts.php`). For high-frequency updates (e.g., live blogs), you may need to increase this or implement a custom cleanup strategy.
- How do I test draft functionality in my Laravel application?
- Use the package’s query scopes (`withoutDrafts()`, `withDrafts()`, `onlyDrafts()`) in your tests to verify draft behavior. Mock the `HasDrafts` trait or use factory methods to create drafts and revisions, then assert their state with assertions like `isPublished()` or `hasDraft()`.
- Will Laravel Drafts work with my existing database schema?
- The package requires 6 additional columns per model, but you can customize column names in the config. If your database is already in production, you’ll need to run migrations carefully—consider batching schema changes per model to minimize downtime.
- Are there alternatives to Laravel Drafts for versioning in Laravel?
- Yes, alternatives include Spatie’s `laravel-activitylog` (for auditing), `spatie/laravel-model-states` (for state-based workflows), or PostgreSQL’s `jsonb` for nested drafts. Laravel Drafts stands out for its simplicity and focus on CMS-style draft/revision workflows without heavy customization.