Streamlining Laravel: Smarter Pruning, Conditional Jobs, and Number Spell Enhancements
Keeping a codebase clean often feels like a never-ending battle against technical debt and database bloat. The latest updates to
Custom Paths for Model Pruning
The model:prune command is a lifesaver for removing old database entries, but it historically expected models to live in the default app/Models directory. If you utilize a modular or domain-driven design, you likely found this restrictive. The new --path argument changes the game. You no longer need to manually specify every individual model class if your files live in custom directories like Context/Newsletter. Simply point the command to your directory, and Laravel will discover your prunable models automatically.
Conditional Logic for Batches and Chains
We have long enjoyed dispatchIf and dispatchUnless for individual jobs. However, applying that same logic to job batches and chains used to require clunky boilerplate code. The framework now treats these complex structures with the same first-class support as single jobs. You can now call Bus::batch([...])->dispatchIf($condition) or chain jobs together with the same conditional fluently. This creates a much more readable developer experience, removing the need for wrapping dispatch logic in manual if statements.
Advanced Spelling with the Number Helper
The Number::spell() helper is fantastic for humanizing data, but sometimes you only want to spell out small numbers while keeping large ones as digits. New after and until arguments provide this exact control. If you set a threshold like Number::spell(11, after: 10), the system will output "eleven." If the input is below that threshold, it returns the raw integer. This is perfect for adhering to strict editorial style guides where numbers one through ten must be words, but anything higher remains numeric.
Refined Consistency Across the Ecosystem
These updates highlight
