In this episode, we take a step back before diving into Laravel's built-in model pruning feature. We explore how you would have handled pruning data manually, which is still super useful for more custom or complex situations.
First, we whip up a simple Artisan console command called prune:deployments
. This command lets us define the logic for finding and deleting old records—in this example, deployments that are older than a week. You'll see how we use Eloquent queries to get the right data, do a quick count to see how many records match, and then actually perform the deletion.
We run the command a couple of times, check our results, and now we've got a clean slate to work with for when we move on to using Laravel's more efficient model pruning out of the box. This episode sets the stage and gives you a good comparison between the "old school" manual approach and what Laravel can soon offer us automatically.