Download the PHP package spinen/laravel-garbage-man without Composer
On this page you can find all versions of the php package spinen/laravel-garbage-man. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spinen/laravel-garbage-man
More information about spinen/laravel-garbage-man
Files in spinen/laravel-garbage-man
Package laravel-garbage-man
Short Description Scheduled job to clean out Laravel's soft deleted records at configured interval.
License MIT
Informations about the package laravel-garbage-man
SPINEN's Laravel Garbage Man
The soft deletes are great in Laravel to make sure that some deleted data can be recovered. This package allows you to configure an array of models with how many days that you want the soft deleted data to stay in the database.
Build Status
Branch | Status | Coverage | Code Quality |
---|---|---|---|
Develop | |||
Master |
Prerequisite
NOTE: If you need to use < PHP 7.2, please stay with version 1.x
As side from Laravel >= 5.1.10 (5.1.10 is the first version that had the warn method, so that is the minimum for logging), there is 1 package that is required.
Install
Install Garbage Man:
For >= Laravel 5.5, you are done with the installation
The package uses the auto registration feature of Laravel 5.
Upgrading to 2.x from 1.x
As of Laravel 5.8 (and deprecated in 5.4), the fire()
method on the dispatcher contract was removed in favor of dispatch()
. Therefore, we have updated our code to use dispatch()
. You will need to change fire()
to dispatch()
in your config/garbageman.php
file.
Using the command
The command is registered with laravel as . You can run it one of 2 ways...
- from the command line
- via a scheduled task.
To automatically run the script as a scheduled job, then add the following to the schedule method of
App\Console\Kernel.php
:
You can use whatever schedule that you need to keep the records purged out. Just review the list at http://laravel.com/docs/master/scheduling#schedule-frequency-options.
You can also use any of the advanced configuration options of the task scheduler like "Task Output" or "Task Hooks" as listed on the Laravel documentation.
Configuration
Publish the package config file to config/garbageman.php
:
This file is fully documented. You will need to make the changes to that file to suit your needs. There are 3 main configuration items...
- Dispatch purge events - Dispatch events on purge of each record.
- Logging level - Level to log.
- Schedule - Models & number of days to allow the soft deleted record to stay before purging.
Dispatch purge events (dispatch_purge_events)
You may hook into the purge of each record by throwing events before & after deleting of each record. There are 2 events thrown:
- garbageman.purging:\<full/model/name>
- garbageman.purged:\<full/model/name>
The model is passed with each of the events. The "purging" event is thrown just before the actual delete & "purged" is thrown just after the actual deletion.
Please note: This is an expensive operation as it requires a SQL command for each record to delete so that the record can be thrown with the events. Therefore, unless you need to catch the events to perform some other action, leave this false to allow all records per model to get deleted with a single SQL call.
Logging level (logging_level)
The level that log messages are generated, which will display information on the console output and in the logs.
Level | Description |
---|---|
0 | Emergency: system is unusable |
1 | Alert: action must be taken immediately |
2 | Critical: critical conditions |
3 | Error: error conditions |
4 | Warning: warning conditions |
5 | Notice: normal but significant condition |
6 (default) | Info: informational messages |
7 | Debug: debug - level messages |
There is a key for the console & one for the log. Here is an example...
Alternatively, you can set the levels with environmental variables and .
Schedule (schedule)
The age is in days for each model. Here is an example...
This would purge any ModelOnes that were deleted over 14 days ago and any ModelTwos that were deleted over 30 days ago.
All versions of laravel-garbage-man with dependencies
illuminate/console Version ~9|~10
illuminate/database Version ~9|~10
illuminate/support Version ~9|~10
nesbot/carbon Version ^2.62.1
psr/log Version ^1.0