Download the PHP package mhdobd/eloquent-relation-guard without Composer
On this page you can find all versions of the php package mhdobd/eloquent-relation-guard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-relation-guard
Eloquent Relation Guard
Laravel package by MuhammadObadaa
Scan, inspect, and (optionally) force‐delete Eloquent models along with their HasOne/HasMany branches—without relying on database‐level cascade or restrict rules.
OnDelete, you can walk through a model’s HasOne/HasMany relations (to any depth), get a nested “tree” of related IDs, check whether a model is safe to delete, or forcibly delete the entire sub‐tree in one shot.
Installation
Require the package via Composer:
Configuration
Publish the configuration file:
This will copy config/eloquent-relation-guard.php into your application’s config/ directory.
Usage
-
Use the Trait in Your Model Add the
HasRelationalDependenciestrait to any Eloquent model you want to protect/scan. -
Check if a Record Can Be Deleted
-
Get the Full Relation “Tree” (with IDs)
-
Force‐Delete a Model and All Related Records
-
Console Command:
record:treeYou can visualize a model’s relation tree (with IDs) from the CLI:Post: The model class name, it should be located inapp/models/directory42: ID of the record to inspect2: Depth (how many nested levels to scan; use-- -1for unlimited)
Example Output:
for more details check the Documentation
TODO
- [ ] Add support for soft deletes (detecting
deleted_atand deciding whether to include or ignore soft‐deleted records). - [ ] Support morph relations along with HasOne and HasMany relations.
- [ ] Allow configurable thresholds for maximum nodes/depth before aborting the scan.
- [ ] Add event hooks (e.g.,
beforeDeleteGuarded,afterDeleteGuarded) so users can tap into the delete process. - [ ] Provide Laravel Nova/Filament integrations for visual “Are you sure?” modals.
- [ ] Mark visited classes when DFS over them so it can avoid cyclic database relations.
- [ ] Write feature tests and include sample migrations/seeders.
- [ ] Add Complexity Details in documentation file.
- [ ] Optimize Time, Memory, and DB Query complexity over core package logic implementation.
Contributing
If you discover bugs, have feature requests, or want to contribute code, please use the GitHub issue tracker:
Issues & Contributions: https://github.com/MuhammadObadaa/eloquent-relation-guard/issues
Feel free to fork the repository, open a PR, and follow these basic guidelines:
- Fork the repo and create a new branch for your feature/fix.
- Write at least one test (where applicable) demonstrating the expected behavior.
- Update
CHANGELOG.mdandREADME.mdif you add or change functionality. - Submit a pull request—describe what you changed and why.
License
Eloquent Relation Guard package is open source, licensed under MIT. Feel free to use, modify, and redistribute.