Laravel Updates

Laravel 12.49.0: Better Enum Support and New Collection Methods

Explore the latest updates in Laravel 12.49.0, featuring expanded PHP Enum support in Sessions and Cache, the new hasSole() collection method, and powerful subquery enhancements for Eloquent. Learn how these performance fixes and DX improvements can sharpen your development workflow.

1 week ago · 3 mins read
Summarize and analyze this article with:
Share this

Laravel 12 continues its rapid release cycle with version 12.49.0. While minor version bumps often feel like routine maintenance, this update introduces several quality-of-life improvements for developers working with enums, complex database queries, and collection pipelines.

Here is a breakdown of the most significant changes in this release.


Enhanced Enum Support Across the Framework

Laravel continues to deepen its first-class support for PHP Enums. In this version, several core methods have been updated to accept enums directly, reducing the need to manually call ->value.

  • Session Management: You can now pass enums directly to Session::now() and Session::flash().
  • Cache & Concurrency: The Cache::flexible() method and the withoutOverlapping() middleware now support enum keys.

This change reduces boilerplate and makes your code more type-safe, especially when using enums to define session keys or cache identifiers.

New Collection Method: hasSole()

The Collection class receives a small but powerful addition with hasSole(). This method is designed for scenarios where you need to verify that exactly one item in a collection matches a given truth test.

// Returns true only if exactly one user is an admin
$isAdminUnique = $users->hasSole(fn ($user) => $user->isAdmin());

It functions similarly to the sole() method but returns a boolean instead of throwing an exception or returning the element, making it ideal for conditional logic.

Query Builder: Subquery "Between" Support

Database enthusiasts will appreciate the new support for "where subquery between columns." This allows for more expressive Eloquent queries where a subquery's result is checked against two different columns in your main table.

$users = User::whereSubquery(function ($query) {
    $query->select('age')->from('profiles')->limit(1);
})->between('min_age', 'max_age')->get();

DX Improvements for CLI and Testing

The developer experience (DX) gets a boost in two specific areas:

  1. Searchable DB Tables: The php artisan db:table The command now uses a searchable prompt. If you have a database with dozens or hundreds of tables, you no longer have to scroll through a massive list; you can simply type to filter.
  2. Testing Assertions: In the QueueFake class, assertPushedTimes has been made public. This allows for more granular testing scenarios when you need to verify the exact number of times a job was dispatched within custom testing wrappers.

Performance and Stability Fixes

Several "under the hood" optimizations were included to keep the framework lean:

  • Memory Management: A memory leak in Arr::dot() was identified and patched.
  • Multibyte Safety: Str::afterLast() now uses multibyte-safe functions, ensuring string manipulation remains reliable for non-ASCII characters.
  • Logging: The framework now skips message serialization if the log level is not handled by the logger, saving cycles on logs that would have been ignored anyway.
  • Parallel Testing: Compiled views are now cleaned up properly after parallel tests finish, preventing "stale view" issues in CI/CD environments.

Is It Safe to Update?

Yes. As a minor release, 12.49.0 maintains full backward compatibility. You can update via Composer:

composer update laravel/framework
Read next

Laravel TALL vs VILT Stack: Features, Tradeoffs, and When to Choose Each

TALL and VILT represent two very different philosophies of building Laravel applications. One keeps logic on the server, the other embraces frontend state. This article explains both approaches clearly and helps you decide which development style aligns with your product goals.

Feb 08 · 1 min read