PHP code example of spatie / laravel-model-cleanup
1. Go to this page and download the library: Download spatie/laravel-model-cleanup 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/ */
spatie / laravel-model-cleanup example snippets
use Illuminate\Database\Eloquent\Model;
use Spatie\ModelCleanup\CleanupConfig;
use Spatie\ModelCleanup\GetsCleanedUp;
class YourModel extends Model implements GetsCleanedUp
{
...
public function cleanUp(CleanupConfig $config): void
{
$config->olderThanDays(5);
}
}
return [
/*
* All models in this array that implement `Spatie\ModelCleanup\GetsCleanedUp`
* will be cleaned.
*/
'models' => [
// App\Models\YourModel::class,
],
];
// in app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command(\Spatie\ModelCleanup\Commands\CleanUpModelsCommand::class)->daily();
}
use Illuminate\Database\Eloquent\Model;
use Spatie\ModelCleanup\CleanupConfig;
use Spatie\ModelCleanup\GetsCleanedUp;
class YourModel extends Model implements GetsCleanedUp
{
...
public function cleanUp(CleanupConfig $config): void
{
$config->olderThanDays(5);
}
}