Download the PHP package sbamtr/laravel-auto-hard-deleter without Composer
On this page you can find all versions of the php package sbamtr/laravel-auto-hard-deleter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sbamtr/laravel-auto-hard-deleter
More information about sbamtr/laravel-auto-hard-deleter
Files in sbamtr/laravel-auto-hard-deleter
Package laravel-auto-hard-deleter
Short Description Laravel Auto Hard Deleter
License MIT
Informations about the package laravel-auto-hard-deleter
Laravel Auto Hard Deleter
[!IMPORTANT]
Archived – This package is no longer maintained.
Laravel now provides a built-in way to prune and automatically delete old models using the Prunable and MassPrunable traits.
Please use Laravel's native pruning feature instead.
Example with Laravel Prunable
Then schedule the pruning command in your routes/console.php
:
This package deletes soft deleted rows automatically after a time interval that you define.
For Laravel and Lumen 6, 7, 8, 9
- Installation
- Usage
- Auto Hard Delete Command
Installation
Step 1
Require the package with composer using the following command:
Step 2
For Laravel
The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php
file:
For Lumen
Add this line of code under the Register Service Providers
section of your bootstrap/app.php
:
Step 3
Now its the time for scheduling the command.
in you app/Console/Kernel.php
file, paste this code in schedule()
function:
In the code above, the command scheduled to run hourly. you can change it. For more information, please read this page.
Step 4 (Optional)
You can publish the config file with this following command:
Note: If you are using Lumen, you have to use this package.
Also you can set the AUTO_HARD_DELETE_AFTER
value in .env
file. like the following code:
Usage
in your models that used SoftDeletes
trait, you can enable Auto Hard Delete with this code:
Just write const AUTO_HARD_DELETE_ENABLED = true
in your models!
Also you can set expiration time for your deleted entities using the following line:
In the code above, expiration time for your soft deleted entity model is 5 months. The final code is:
You can set any other values for AUTO_HARD_DELETE_AFTER
like 5
(means 5 days), 2 hours
, 45 days
, 2.5 months
, 1 year
, etc.
Note: If you don't set any value for AUTO_HARD_DELETE_AFTER
in your model, the soft deleted models with AUTO_HARD_DELETE_ENABLED = true
will be hard deleted after the time defined in config file named auto-hard-deleter.php
.
Auto Hard Delete Command
Also you can hard delete expired rows manually using this artisan command:
Written with ♥ by Siavash Bamshadnia
Please support me by staring this repository.
All versions of laravel-auto-hard-deleter with dependencies
illuminate/console Version ^6|^7|^8|^9
illuminate/database Version ^6.20.12|^7.30.4|^8.22.1|^9
illuminate/support Version ^6|^7|^8|^9