Download the PHP package hith/laravel-eraser without Composer
On this page you can find all versions of the php package hith/laravel-eraser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-eraser
Laravel Eraser
Laravel Eraser focuses on Erasing Eloquent Model Relation. It has two modes of operation.
- Manual: this mode require the developer to define erasable array contains relations should be deleted
- Auto: this mode use auto-discover for relations to be deleted
Supported Laravel versions
| Laravel Version | Eraser Version |
|---|---|
| 12.x | 1.0+ |
Getting Started
Requires:
1: First, use Composer to install laravel-eraser into your project:
2: Then, publish config file:
3: Finally, Use the package in two ways:
- By adding traits directly to your models.
- By using the Eraser class to delete/clean models.
Usage of traits:
-there are two types of traits [manual , auto]:
Manual Eraser Trait:
Then instead of:
Simply do:
Or, if you just want to clear relations without deleting the model:
Auto Eraser Trait:
As with the manual trait, simply do:
The user() relation will not be deleted in either mode, as it is considered a parent relation.
Usage of Eraser Class:
-
Manual Mode (default):
- Auto Mode
Usage of Eraser Facade:
Eraser Configuration
You can alter the behavior of the eraser either globally using the eraser config file or by defining some of this attributes on the model.
Best practices
Logging: Keep logging enabled in development/staging;
Testing: Validate deletion flows, including parent relations and many-to-many detaches, before production.
Deny list: Extend eraser_base_deny_list to match your naming patterns for utility methods.
Mode choice: Use manual mode for sensitive domains (users, orders); auto mode for convenience on simpler models.
Ownership safety: Parent relations (BelongsTo, MorphTo) are skipped to preserve ownership chains and to prevent circular deletion loops.
Pivot hygiene: Many-to-many are detached; ensure pivot constraints and cascades are correct.
Model Relationships:
In order for Eraser (auto-discover) to recognize Model relationships the following is recommended:
- the return type must be defined
- the method must be
public - the method has no arguments
Log Outputs Example
Info
[info] Processing: Post[42]
[info] Processing relation 'comments'
[info] Relation 'comments' processed
Skipped
[info] Skipping parent relation 'author'
[info] Skipping already processed Post:42
Warning
[warning] Missing 'erasable' on Post
[warning] Method 'likes' did not return a Relation
Error
[error] Relation 'tags' not found on Post
[error] Error deleting relation 'images': Call to undefined method
Contributing
Thank you for considering contributing to Laravel Eraser. All the contribution guidelines are mentioned here.
License
Laravel Eraser is an open-sourced software licensed under the MIT license.