1. Go to this page and download the library: Download devsarfo/laraprunable 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/ */
devsarfo / laraprunable example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use DevSarfo\LaraPrunable\Traits\SoftPrunable;
class Post extends Model
{
use SoftDeletes, SoftPrunable;
/**
* Get the prunable model query.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function prunable()
{
return static::where('deleted_at', '<=', now()->subDays(30));
}
/**
* Prepare the model for pruning.
*
* @return void
*/
protected function pruning()
{
// Perform any cleanup before pruning
// e.g., delete related files, log activity, etc.
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use DevSarfo\LaraPrunable\Traits\SoftMassPrunable;
class Comment extends Model
{
use SoftDeletes, SoftMassPrunable;
/**
* Get the prunable model query.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function prunable()
{
return static::where('deleted_at', '<=', now()->subDays(7));
}
}
// In routes/console.php
use Illuminate\Support\Facades\Schedule;
Schedule::command('model:prune')->daily();
// In app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('model:prune')->daily();
}