- How do I install romanzipp/laravel-previously-deleted?
- Run composer require romanzipp/laravel-previously-deleted, then publish the migration with php artisan vendor:publish and run php artisan migrate. Add the package trait to each Eloquent model whose deletes you want to record. The integration surface is minimal: one use statement per model plus the previously_deleted table.
- Does this package work with Laravel 9, 10 or 11?
- Not unmodified. The last release was in March 2020 for the Laravel 6 era, and its illuminate/* constraints will not admit Laravel 9, 10 or 11 without edits. PHP 8.x will also likely surface dynamic-property deprecations and overridden-method return-type errors, so plan to fork and patch before running it on a modern stack.
- What is the difference between laravel-previously-deleted and SoftDeletes?
- SoftDeletes keeps the row in the original table and just hides it from queries, while this package hooks the Eloquent deleted event and serializes getAttributes() into a separate polymorphic previously_deleted table. It is designed for hard deletes issued through Eloquent, so it is conceptually redundant with SoftDeletes. Do not run both traits on the same model.
- Does it capture bulk deletes or DB-level cascade deletes?
- No. Eloquent model events do not fire for query-builder bulk deletes such as Model::where(...)->delete(), and they do not fire for database-level ON DELETE CASCADE. Cascade-deleted child rows are silently lost, which is often exactly the data you wanted to recover. Inventory your production delete paths before relying on this package.
- What data is stored in the previously_deleted table?
- Each record stores the model type, the model key and a JSON payload built from getAttributes(). That means column values only: no relations, no media or files, and no guarantee that cast values round-trip correctly. Wide models also produce large payloads, so check against MySQL max_allowed_packet or Postgres TOAST limits.
- Can I restore a deleted model, and does it bring back relations?
- Restore is a re-insert of the stored attributes, not a true undo. Relations, files and media are not restored, and the original ID, foreign keys and unique constraints may collide with data created after the delete. Treat restore as a recovery helper for recent accidental deletes rather than a complete rollback mechanism.
- How do I test this package in a Laravel application?
- Add the trait to a test model, delete a record through Eloquent, and assert that a row exists in previously_deleted with the expected model_type, model_id and JSON payload. Add coverage for your actual delete paths, including bulk deletes and cascades, so you know what is not captured. Verify behavior against your exact Laravel minor and database engine before trusting it in production.
- Is it safe to store deleted records containing passwords or PII?
- The package implies no encryption, redaction or access control, so full snapshots can include password hashes, API tokens and personal data. That second copy also complicates GDPR erasure requests because there are now two places to purge. Add encryption at rest or field redaction, plus a retention and garbage-collection job, before using it on sensitive tables.
- How does it compare to spatie/laravel-activitylog or owen-it/laravel-auditing?
- Both audit packages are actively maintained and cover much of the same ground, including change history and who made changes. If your requirement is auditable history rather than recovering accidental deletes, an audit package is usually the better fit. If you only need a short recovery window, a roughly 150-line in-house observer and table may be simpler than adopting this dependency.
- Is romanzipp/laravel-previously-deleted still maintained?
- No. The last release was in March 2020, there are no commits since, and it has very few stars and dependents with no community support or security advisories. Treat it as code you are adopting rather than a dependency you are consuming, and assign a named owner to maintain a fork. That maintenance cost recurs at every Laravel and PHP upgrade.