Laravel 12.21.0 – A Smart Update for Cleaner Queries and Stricter Validation
August 3, 2025Laravel 12.21.0 introduces two game-changing features aimed at writing cleaner, more maintainable code. The update includes the new whereValueBetween() method and stricter validation rules for boolean and numeric fields.
1. whereValueBetween() : Elegant Range Filtering Across Two Columns
The new whereValueBetween() method allows you to check if a given value (such as user age or order amount) lies between the values of two different columns—without writing complex raw conditions. Here's how it works:
$users = DB::table('users')
->whereValueBetween('age', 'min_age', 'max_age')
->get();
Previously, you'd have to write something like this:
$users = DB::table('users')
->whereColumn('min_age', '<=', 'age')
->whereColumn('max_age', '>=', 'age')
->get();
With whereValueBetween() , your query is cleaner and more expressive, aligning better with the intent of your logic—this leads to easier debugging and more readable code.
2. Stricter Validation: Better Accuracy, Fewer Surprises
Laravel 12.21.0 also brings improvements to data validation by applying strict rules to 'accepted' and 'numeric' validations.
What's changed:
'accepted': Now only accepts valuestrue,'1', or1. Other values like'yes'or'on'will fail the validation.'numeric': Rejects non-numeric values such asnullor'abc', even if they are string representations.
This change improves input reliability and prevents invalid data from being mistakenly accepted—especially helpful when users interact with your front-end carelessly or maliciously.
3. Real-World Benefits
These enhancements provide you with:
- Less repetitive code in complex query logic
- More accurate validation and fewer bugs caused by bad input
- Cleaner code that aligns with SOLID principles and Clean Code standards
4. How to Start Using These Features
- Make sure your Laravel installation is updated to 12.21.0 or later.
- Use whereValueBetween() whenever you need to compare a value across two columns.
- Revisit your validation logic to benefit from the stricter checks in 'accepted' and 'numeric' .
💡 Pro Tip: Run your test suite after upgrading to ensure your application behaves exactly as expected.
Blog
React Native 0.80 & ExecuTorch: A Powerful Leap into Offline AI for Mobile Apps
Jul 28, 2025
🚀 What’s New in React Native 0.80? The React Native 0.80 release marks a pivotal moment in mobile development. This update not only enhances...
Supercharge Your PHP Enums with archtechx/enums
Jul 01, 2025
Supercharge Your PHP Enums with archtechx/enums PHP 8.1 introduced native enums—type‑safe sets of named values like statuses or roles. The arch...
Mastering Async Iteration in JavaScript with Array.fromAsync()
Jul 27, 2025
🔍 What Exactly is Array.fromAsync()? Array.fromAsync() is a static method introduced in ES2024 as part of JavaScript's growing support for asynchr...
Mastering Laravel Context: Advanced Logging and Contextual Job Tracing
Jul 20, 2025
Laravel Context is one of the most powerful new features in Laravel 12. It allows you to attach contextual data (like user ID, IP address, request pat...
React Labs: View Transitions & Activity
Jun 17, 2025
React Labs: View Transitions & Activity Published April 23, 2025 by Ricky Hanlon. React Labs is sharing two new experimental featu...
React History – A Professional Developer’s Perspective
Jul 26, 2025
1. Origins: Born Inside Facebook In 2011, Facebook engineers faced the increasing complexity of building interactive UIs at scale. They developed...