https://github.com/dillingham/soft-deletes-parent
Laravel soft delete children when parent soft deletes
https://github.com/dillingham/soft-deletes-parent
Last synced: 11 months ago
JSON representation
Laravel soft delete children when parent soft deletes
- Host: GitHub
- URL: https://github.com/dillingham/soft-deletes-parent
- Owner: dillingham
- License: mit
- Created: 2021-10-19T15:56:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-19T19:52:30.000Z (over 4 years ago)
- Last Synced: 2025-06-15T16:45:59.020Z (about 1 year ago)
- Language: PHP
- Size: 24.4 KB
- Stars: 59
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Laravel Soft Deletes Parent
[](https://packagist.org/packages/dillingham/soft-deletes-parent)
[](https://github.com/dillingham/soft-deletes-parent/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/dillingham/soft-deletes-parent/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[](https://packagist.org/packages/dillingham/soft-deletes-parent)
---
Automatically soft delete a model's children while maintaining their own soft deleted state when you restore the parent model. After installing the trait below, the `Post` model's `parent_deleted_at` will update whenever an `Author` model is deleted or restored. This allows you to maintain the original `deleted_at` for the `Post` model after `Author` is restored. The `Post` model will scope queries to exclude any where the parent is deleted.
---
## Installation
You can install the package via composer:
```bash
composer require dillingham/soft-deletes-parent
```
## Usage
Add the `parent_deleted_at` column to your table:
```php
Schema::table('posts', function (Blueprint $table) {
$table->softDeletesParent();
});
```
And add the trait and parent model to your child model:
```php
get();
```
Only parent trashed:
```php
Post::onlyParentTrashed()->get();
```
## Testing
```bash
composer test
```
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Brian Dillingham](https://github.com/dillingham)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.