What is Laravel model pruning?
Answer
Model pruning (Laravel 8+) automatically deletes models that are no longer needed. Implement the Prunable trait and define a prunable() method that returns a query builder for records to delete: public function prunable(): Builder { return static::where("created_at", "<=", now()->subMonth()) }. Schedule pruning: $schedule->command("model:prune")->daily(). Prune specific models: php artisan model:prune --model=User. For soft-deleted models, use MassPrunable for more efficient bulk deletion (single DELETE query rather than loading each model). Add a pruning() method for cleanup logic before deletion. Model pruning replaces custom scheduled commands for database maintenance tasks like removing old log entries, expired tokens, temporary uploads, and stale verification codes.