Download the PHP package codenco-dev/laravel-eloquent-pruning without Composer
On this page you can find all versions of the php package codenco-dev/laravel-eloquent-pruning. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codenco-dev/laravel-eloquent-pruning
More information about codenco-dev/laravel-eloquent-pruning
Files in codenco-dev/laravel-eloquent-pruning
Package laravel-eloquent-pruning
Short Description We often have to clean up our oldest or unnecessary records. This package does it easily for us.
License MIT
Homepage https://github.com/codenco-dev/laravel-eloquent-pruning
Informations about the package laravel-eloquent-pruning
Easily prune your Eloquent Model Records
We often have to clean up the records of our databases by deleting the oldest and useless data. This package allows, via Eloquent models, to make this easier.
Installation
You can install the package via composer:
Configuration
We have several options that can be configure.
pruning_column
- The name of the column that will be used to determine if a record should be prunedhours
- The hours count that will determine if a record should pruned relative to pruning_column and now datetimewith_delete_events
- If the value is true, the delete method of model will be call, allowing fire events. If the value is false, the delete action will be done with query builder, without event.chunk_size
- The size of delete query if with_delete_events is false
If all prunable models have the same configuration, you can do it in the laravel-eloquent-pruning
file.
You can publish configuration file with this command line
If all prunable models don't have the same configuration, each options for a model can be defined in the model file like this :
If you need something more elaborate, you be able to overwrite, Prunable
trait methods.
In configuration file, you can manage default value for the Pruning Package. You must define models that will be affected by pruning.
If some records can't be prune, with business logic, you can use this methods :
If with_delete_events
is false, the business logic must be put in scopeCouldBePruned
like this
If with_delete_events
is true, the business logic can be put in scopeCouldBePruned
but also by overwrite canBePruned
method like this
Usage
You can add global pruning on your schedule by modifying app/Console/Kernel.php
like this for example
If you want bypass model hour configuration, you can call this command with hours
option like this :
This call allows to prune all data created more than 48 hours ago.
Of course, you can use a schedule by model (or create a dedicated command if you want) :
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Dominic Thomas
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
Inspiration
This package was inspired by laravel/telescope pruning.