New in Laravel 8.50: You can use the Prunable trait to automatically remove models from your database. For example, you can permanently remove soft deleted models after a few days.
1class File extends Model 2{ 3 use SoftDeletes; 4 5 // Add Prunable trait 6 use Prunable; 7 8 public function prunable() 9 {10 // Files matching this query will be pruned11 return static::query()->where('deleted_at', '<=', now()->subDays(14));12 }13 14 protected function pruning()15 {16 // Remove the file from s3 before deleting the model17 Storage::disk('s3')->delete($this->filename);18 }19}20 21// Add PruneCommand to your schedule (app/Console/Kernel.php)22$schedule->command(PruneCommand::class)->daily();
Tip by @Philo01