PHP code example of iamankitthapar / laravel-data-retention
1. Go to this page and download the library: Download iamankitthapar/laravel-data-retention 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/ */
iamankitthapar / laravel-data-retention example snippets
namespace App\Providers;
use App\Models\ApiLog;
use Iamankitthapar\DataRetention\Facades\Retention;
use Illuminate\Support\ServiceProvider;
class RetentionServiceProvider extends ServiceProvider
{
public function boot(): void
{
Retention::rule('old-api-logs')
->model(ApiLog::class)
->olderThan('created_at', '6 months')
->action('delete')
->limit(10);
}
}
->>onlySoftDeleted() // Match only soft-deleted records.
->connection('mysql')
->schedule('daily')
->schedule('cron:0 2 * * *', 'Asia/Kolkata')
use Iamankitthapar\DataRetention\Facades\Retention;
Retention::schedule();
Retention::scheduleStoredPolicies();
use Iamankitthapar\DataRetention\Facades\Retention;
use Illuminate\Console\Scheduling\Schedule;
protected function schedule(Schedule $schedule): void
{
Retention::schedule($schedule);
Retention::scheduleStoredPolicies($schedule);
}