What is Laravel model pruning?
Why Interviewers Ask This
Senior Laravel engineers are expected to reason about architecture, performance, and edge cases. This question separates mid-level from senior candidates by testing deep system-level understanding.
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.
Pro Tip
This topic has Laravel-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.