1. Go to this page and download the library: Download kaveraa/data-lifecycle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kaveraa / data-lifecycle example snippets
#[KeepFor('3 years')] // kept 3 years after the last sign of life
#[WarnBefore('30 days')] // an email 30 days before the deadline
#[DisableFirst('30 days')] // disabled, then 30 days to come back
#[ThenAnonymise('email', 'name')] // after that the row stays, but anonymous
class User
{
}
use Kaveraa\DataLifecycle\Attribute\DisableFirst;
use Kaveraa\DataLifecycle\Attribute\KeepFor;
use Kaveraa\DataLifecycle\Attribute\ThenAnonymise;
use Kaveraa\DataLifecycle\Attribute\ThenDelete;
use Kaveraa\DataLifecycle\Attribute\WarnBefore;
use Kaveraa\DataLifecycle\Strategy;
#[KeepFor('3 years')]
#[WarnBefore('30 days')]
#[WarnBefore('7 days')]
#[DisableFirst('30 days')]
#[ThenAnonymise('email', 'name', ['birth_date' => Strategy::YearOnly])]
class User extends Authenticatable
{
}
#[KeepFor('90 days', since: 'sent_at')]
#[ThenDelete]
class Invitation
{
}
use Kaveraa\DataLifecycle\Event\SubjectWarned;
Event::listen(function (SubjectWarned $event): void {
$user = $event->entity();
Mail::to($user)->send(new AccountExpiring(
dueAt: $event->dueAt, // date of the disabling
reminder: $event->warnIndex, // 0 for the first reminder, 1 for the next one
));
});
use Kaveraa\DataLifecycle\Lifecycle;
public function login(Request $request, Lifecycle $lifecycle)
{
// ...
$lifecycle->reactivate($user); // no more reminder, no more disabling, clock back to zero
}
$lifecycle->stageOf($user); // Stage::Active, Warned, Disabled or Erased
$lifecycle->dueAt($user); // date of the coming disabling
use Kaveraa\DataLifecycle\Laravel\Concerns\HasLifecycle;
class User extends Authenticatable
{
use HasLifecycle;
}
User::active()->count();
User::disabled()->get();
$user->lifecycleStage();
$user->lifecycleDueAt();
$user->reactivate();
bash
php artisan lifecycle:install
bash
php artisan lifecycle:run # everything, for real
php artisan lifecycle:run --dry-run # without writing anything
php artisan lifecycle:run --subject="App\Models\User"
php artisan lifecycle:run --step=warn # only the reminders
php artisan lifecycle:run --limit=500 # at most 500 rows per step
bash
php artisan lifecycle:run --step=warn --limit=200 # for 30 days
php artisan lifecycle:run # after that
bash
php artisan lifecycle:report
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.