Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

`hasSole()` Collection Method in Laravel 12.49.0

Last updated on by

`hasSole()` Collection Method in Laravel 12.49.0 image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

Release Date: January 28, 2026 Laravel Version: 12.49.0

Summary

Laravel v12.49.0 introduces a new hasSole() collection method for checking if a collection contains exactly one matching item, along with subquery between columns support, fluent resource collection key preservation, and datetime support for the maintenance mode command. This release also expands enum support across session and cache components.

Key highlights include:

  • New hasSole() collection method (deprecates containsOneItem())
  • Subquery between columns in the query builder
  • preserveKeys() method for fluent resource collection chaining
  • Datetime values for down --retry option
  • Enum support for Session now() and flash() methods
  • Enum keys in Cache::flexible() and withoutOverlapping()
  • Searchable prompt for db:table command
  • Memory leak fix in Arr::dot()

What's New

hasSole() Collection Method

Laravel 12.49.0 adds the hasSole() method to collections, providing a concise way to check if a collection contains exactly one item matching specified criteria. This method aligns with Laravel's existing sole() nomenclature and deprecates the older containsOneItem() method.

// Check if collection has exactly one item
$collection->hasSole();
 
// With a callback filter
$collection->hasSole(fn ($item) => $item->active);
 
// With key/value pair
$collection->hasSole('status', 'pending');
 
// With operator syntax
$collection->hasSole('age', '>=', 21);

The method supports the same flexible filter signatures as sole(), making it intuitive for developers already familiar with Laravel's collection API.

Pull Request: #58463

Subquery Between Columns

The query builder now supports comparing a subquery result against two database columns using whereBetweenColumns():

$query->whereBetweenColumns($subquery, ['min_value', 'max_value']);

This allows you to check if a subquery result falls between dynamic column values from the table, rather than hardcoded constants. This is a follow-up to previous work adding subquery support with static value ranges.

Pull Request: #58441

preserveKeys() for Resource Collections

The AnonymousResourceCollection now includes a preserveKeys() method for fluent chaining, eliminating the need for intermediate variable assignment:

// Before
$collection = JsonResource::collection($posts);
$collection->preserveKeys = true;
return $collection;
 
// After
return JsonResource::collection($posts)->preserveKeys();

This improvement makes resource collection configuration more readable and consistent with Laravel's fluent API patterns.

Pull Request: #58443

Datetime Support for Down Command

The php artisan down command's --retry option now accepts datetime strings in addition to numeric seconds:

# Retry at a specific datetime
php artisan down --retry="2026-01-28 15:30:00"
 
# Retry tomorrow at 2 PM
php artisan down --retry="tomorrow 14:00"
 
# Retry in 2 hours
php artisan down --retry="+2 hours"
 
# Unix timestamp
php artisan down --retry="@1735660200"

The datetime is converted to RFC 7231 format for the Retry-After header. A warning is displayed if a past datetime is provided, helping prevent configuration errors during maintenance windows.

Pull Request: #58509

Expanded Enum Support

This release continues Laravel's enum integration by adding support in additional locations:

Session Methods: The now() and flash() session methods now accept enum values as keys, bringing them into consistency with other session methods.

Pull Request: #58459

Cache Methods: Cache::flexible() and Cache::withoutOverlapping() now accept enum keys, allowing for type-safe cache key management.

Pull Request: #58444

Searchable db:table Prompt

The php artisan db:table command now uses a searchable prompt for table selection, making it easier to find tables in databases with many tables.

Pull Request: #58442

Bug Fixes and Improvements

Bug Fixes:

  • Fixed memory leak in Arr::dot() (#58458)
  • Use multibyte-safe functions in Str::afterLast() (#58457)
  • Clean up compiled views after parallel testing (#58440)
  • Skip message serialization when log level not handled (#58475)
  • Ignore deadlock on DatabaseLock release (#58507)
  • Use assignment instead of mutation for immutable Carbon objects (#58498)

Improvements:

  • Keep single NotificationSender instance for better performance (#58452)
  • Make QueueFake::assertPushedTimes public (#58511)
  • Enhanced index hint validation for multiple indexes (#58505)
  • Added missing @param documentation to SessionGuard constructor (#58493)
  • Bumped tar dependency from 7.5.3 to 7.5.6 (#58454)

Reverts:

  • Reverted "aliasing when selecting database expressions" feature (#58469)

Upgrade Notes

No breaking changes are expected for typical applications. Review the full changelog for complete details when upgrading.

References

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SerpApi logo

SerpApi

Access real-time search engine results through a simple API—no more scraping headaches! Use it for AI applications, SEO tools, product research, travel information, and more

SerpApi
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review

The latest

View all →
Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel image

Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel

Read article
Generate HTML Password Rules Attribute in Laravel 13.9.0 image

Generate HTML Password Rules Attribute in Laravel 13.9.0

Read article
DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell image

DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell

Read article
Model-Based Scheduling for Laravel with Cadence image

Model-Based Scheduling for Laravel with Cadence

Read article
Laravel's AI SDK adds sub-agents image

Laravel's AI SDK adds sub-agents

Read article
Laravel Introduces First-Party Passkey Authentication Support image

Laravel Introduces First-Party Passkey Authentication Support

Read article