- How do I add publishable functionality to an existing Laravel Eloquent model?
- Use the `Publishable` trait in your model and add the `publishable()` macro to your migration. The package handles the rest, including the 4-state workflow (draft, published, unpublished, scheduled) and `published_first_at` field for sorting. No base class inheritance is required.
- Does this package work with Laravel 10 and PHP 8.2+?
- Yes, the package explicitly requires Laravel 10+ and PHP 8.2+. Older versions may need a separate branch or manual adjustments. Always check the [GitHub repository](https://github.com/novius/laravel-publishable) for version-specific docs.
- Can I use this package with Laravel Nova for a content management interface?
- The core package works with vanilla Laravel, but the `novius/laravel-nova-publishable` extension adds Nova-specific tooling like toolbars and filters. You’ll need to install both packages and configure Nova resources separately for full UI integration.
- How do I enforce publish permissions (e.g., only admins can publish content)?
- The package doesn’t include built-in authorization. Use Laravel’s Policies, Gates, or Middleware to validate publish/unpublish actions. For example, create a `PublishPost` policy or middleware to check user roles before state transitions.
- Will this package work with Laravel’s SoftDeletes trait?
- Yes, but conflicts must be handled explicitly. For example, a soft-deleted record cannot be unpublished. Use observers or model events to manage state transitions carefully, or disable SoftDeletes for publishable models if needed.
- How do I backfill the `published_first_at` and status fields for existing tables?
- Use a data migration or a separate script to populate these fields. The package doesn’t provide a one-click solution, so you’ll need to write custom logic—either via a migration or a command—to update records without downtime.
- Does this package support scheduled posts with timezone handling?
- The package uses Laravel’s default timezone (`config('app.timezone')`) for scheduled posts, but edge cases (e.g., daylight saving) may require custom logic. Test thoroughly or extend the trait to handle timezone-specific validation or adjustments.
- How do I cache published/unpublished states to improve performance?
- The package doesn’t include caching logic, but you can integrate it with Laravel’s cache drivers. Use events (e.g., `published`, `unpublished`) to invalidate caches like Redis or Varnish. For example, trigger `Cache::forget()` or `tags:clear` in observers.
- What are the risks of using this package in a production SaaS application?
- The AGPL-3.0 license may conflict with proprietary SaaS unless relicensed. Also, the package lacks built-in validation for state transitions (e.g., who can publish) and requires manual handling of SoftDeletes conflicts. Test thoroughly and consider custom extensions for critical workflows.
- Are there alternatives to this package for publishable content in Laravel?
- Yes, alternatives include `spatie/laravel-activitylog` (for audit logs) combined with custom state management, or packages like `orchid/platform` (for CMS workflows). However, this package offers a lightweight, Eloquent-focused solution with built-in scopes and macros for common use cases.