Download the PHP package yousef-aman/prevent-deletion without Composer
On this page you can find all versions of the php package yousef-aman/prevent-deletion. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yousef-aman/prevent-deletion
More information about yousef-aman/prevent-deletion
Files in yousef-aman/prevent-deletion
Package prevent-deletion
Short Description A package to prevent deletion of models with related records.
License MIT
Informations about the package prevent-deletion
Prevent Deletion
A Laravel package to prevent the deletion of models with related records.
Installation
Method 1: Install via Packagist
- Run the following command to require the package:
Method 2: Install via GitHub
-
Add the following repository to your
composer.json
file: - Run the following command to require the package:
Usage
Step 1: Use the Trait in Your Models
Use the PreventDeletionIfHasRelations
trait in your models. Define any specific conditions, and optionally, specify which relationships to exclude or include in the check.
Example: User Model
Example: Blog Model
Step 2: Handle Deletion in Controllers
Handle the exception in your controller to provide a user-friendly message:
Features
1. Custom Exception Handling
The package uses a custom PreventDeletionException
class to handle exceptions specifically related to deletion prevention. This makes it easier to catch and handle these exceptions separately from other types of exceptions.
2. Logging
The package integrates logging to record attempts to delete models with related records. This helps in debugging and monitoring.
3. Configurable Messages
Models can define custom messages for deletion prevention scenarios, making the package more flexible.
4. Extending Configuration
The package allows for detailed control over which relations are checked by specifying excludedRelations
and includedRelations
.
Contributing
Thank you for considering contributing to this package! You can contribute by opening an issue or submitting a pull request.
License
This package is open-source software licensed under the MIT license.