You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2024. It is now read-only.
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.
@@ -17,7 +16,7 @@ The soft deletes are great in Laravel to make sure that some deleted data can be
17
16
18
17
## Prerequisite
19
18
20
-
#### NOTE: If you need to use < php7.2, please stay with version 1.x
19
+
#### NOTE: If you need to use < PHP 7.2, please stay with version 1.x
21
20
22
21
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.
23
22
@@ -28,67 +27,67 @@ As side from Laravel >= 5.1.10 (5.1.10 is the first version that had the warn me
28
27
Install Garbage Man:
29
28
30
29
```bash
31
-
$ composer require spinen/laravel-garbage-man
30
+
$ composer require spinen/laravel-garbage-man
32
31
```
33
32
34
-
### For >= Laravel 5.5, you are done with the Install
33
+
### For >= Laravel 5.5, you are done with the installation
35
34
36
-
The package uses the auto registration feature
35
+
The package uses the [auto registration feature](https://laravel.com/docs/5.8/packages#package-discovery) of Laravel 5.
37
36
38
37
## Upgrading to 2.x from 1.x
39
38
40
-
As of Laravel 5.4, the `fire()` method on the dispatcher contract [was deprecated](https://laravel.com/docs/5.4/upgrade) in favor of `dispatch()`, and as of 5.8 the `fire()` method has been removed. Therefore, we have updated our code to use `dispatch()`. You will need to change `fire()` to `dispatch()` in your `config/garbageman.php` file.
39
+
As of Laravel 5.8 (and deprecated in 5.4), the `fire()` method on the dispatcher contract [was removed](https://laravel.com/docs/5.8/upgrade) 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.
41
40
42
41
## Using the command
43
42
44
43
The command is registered with laravel as ```garbageman:purge```. You can run it one of 2 ways...
45
44
46
45
1. from the command line ```php artisan garbageman:purge;```
47
-
2. via scheduled task.
46
+
2. via a scheduled task.
48
47
49
-
To automatically run the script as a scheduled job, then add the following to the schedule method of
48
+
To automatically run the script as a scheduled job, then add the following to the schedule method of
50
49
`App\Console\Kernel.php`:
51
50
52
51
```php
53
-
$schedule->command('garbageman:purge')
54
-
->daily();
52
+
$schedule->command('garbageman:purge')
53
+
->daily();
55
54
```
56
55
57
-
You can use whatever schedule that you need to keep the records purged out. Just review the list at
56
+
You can use whatever schedule that you need to keep the records purged out. Just review the list at
Allow hook into the purge of each record by throwing events before & after deleting of each record. There are 2 events thrown:
78
+
You may hook into the purge of each record by throwing events before & after deleting of each record. There are 2 events thrown:
80
79
81
80
* garbageman.purging:\<full/model/name\>
82
81
* garbageman.purged:\<full/model/name\>
83
82
84
-
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 delete.
83
+
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.
85
84
86
-
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 preform some other action, leave this false to allow all records per model to get deleted with a single SQL call.
85
+
**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.
87
86
88
87
### Logging level (logging_level)
89
88
90
89
The level that log messages are generated, which will display information on the console output and in the logs.
91
-
90
+
92
91
| Level | Description |
93
92
| :---: | ----------- |
94
93
| 0 | Emergency: system is unusable |
@@ -99,14 +98,14 @@ The level that log messages are generated, which will display information on the
99
98
| 5 | Notice: normal but significant condition |
100
99
| 6 (default) | Info: informational messages |
101
100
| 7 | Debug: debug - level messages |
102
-
101
+
103
102
There is a key for the console & one for the log. Here is an example...
104
103
105
104
```php
106
-
'logging_level' => [
107
-
'console' => 3,
108
-
'log' => 6,
109
-
],
105
+
'logging_level' => [
106
+
'console' => 3,
107
+
'log' => 6,
108
+
],
110
109
```
111
110
112
111
Alternatively, you can set the levels with environmental variables ```GARBAGEMAN_CONSOLE_LOG_LEVEL``` and ```GARBAGEMAN_LOG_LEVEL```.
@@ -116,9 +115,9 @@ Alternatively, you can set the levels with environmental variables ```GARBAGEMAN
116
115
The age is in days for each model. Here is an example...
117
116
118
117
```php
119
-
'schedule' => [
120
-
App\ModelOne::class => 14,
121
-
App\ModelTwo::class => 30,
122
-
],
118
+
'schedule' => [
119
+
App\ModelOne::class => 14,
120
+
App\ModelTwo::class => 30,
121
+
],
123
122
```
124
123
This would purge any ModelOnes that were deleted over 14 days ago and any ModelTwos that were deleted over 30 days ago.
0 commit comments