News

Laravel 12.45.1, 12.45.2, and 12.46.0 Released

Published
Laravel 12.45.1, 12.45.2, and 12.46.0 Released image

Release updates

Never miss a Laravel release

Get an email whenever a new Laravel release lands.

Release Date: January 7, 2026
Laravel Versions: 12.45.1, 12.45.2, 12.46.0

Summary

Laravel released three new framework versions on January 7, 2026, bringing valuable new array and collection helpers, enhanced Gate authorization with enum support, and several important bug fixes. Version 12.46.0 introduces Arr::onlyValues() and Arr::exceptValues() methods for value-based array filtering, plus a new Collection::containsManyItems() method for checking multiple items. Version 12.45.2 adds UnitEnum support to the Gate's has() method, while 12.45.1 fixes a critical issue with ResourceCollections.

Key highlights include:

  • New Arr::onlyValues() and Arr::exceptValues() helper methods for filtering arrays by value
  • Collection::containsManyItems() method for efficient multi-item checks
  • UnitEnum support in Gate's has() method for type-safe authorization
  • Fixes for ResourceCollection array handling and validator rule appending
  • MySQL DDL locking options support
  • Database connection table prefix cloning fix

What's New

New Array Value Filtering Methods

Laravel 12.46.0 introduces two new array helper methods: Arr::onlyValues() and Arr::exceptValues(). These methods complement the existing Arr::only() and Arr::except() helpers by filtering arrays based on their values rather than keys.

The Arr::onlyValues() method filters an array to keep only items whose values match the specified values:

use Illuminate\Support\Arr;
 
$roles = ['admin', 'editor', 'viewer', 'guest'];
 
$allowedRoles = Arr::onlyValues($roles, ['admin', 'editor']);
// Result: [0 => 'admin', 1 => 'editor']

The Arr::exceptValues() method does the opposite, removing items whose values match the specified values:

$statuses = ['pending', 'completed', 'failed', 'shipped'];
 
$activeStatuses = Arr::exceptValues($statuses, ['failed', 'completed']);
// Result: [0 => 'pending', 3 => 'shipped']

Both methods support strict type comparison via an optional third parameter, which is particularly useful when working with mixed-type arrays:

$mixedValues = [1, '1', 2, '2', 3];
 
$integers = Arr::onlyValues($mixedValues, [1, 2, 3], strict: true);
// Result: [0 => 1, 2 => 2, 4 => 3] - only exact type matches

These methods are useful for filtering configuration arrays, removing specific status values, data sanitization based on value allowlists/denylists, and cleaning up form input values.

Pull Request: #58317

Collection Contains Many Items Method

Laravel 12.46.0 adds a new containsManyItems() method to the Collection class. This method determines if a collection contains more than one item, complementing the existing containsOneItem() method.

Basic usage checks if a collection has multiple items:

collect([])->containsManyItems(); // false
collect([1])->containsManyItems(); // false
collect([1, 2])->containsManyItems(); // true
collect([1, 2, 3])->containsManyItems(); // true

The method also accepts an optional callback to check if multiple items match a specific condition:

$users = collect([
['name' => 'John', 'role' => 'admin'],
['name' => 'Jane', 'role' => 'editor'],
['name' => 'Bob', 'role' => 'admin'],
]);
 
// Check if there are multiple admins
$hasMultipleAdmins = $users->containsManyItems(fn($user) => $user['role'] === 'admin');
// Result: true

This method is particularly useful in validation logic to ensure multiple options are selected:

$selectedOptions = collect($request->input('options'));
 
if (! $selectedOptions->containsManyItems()) {
throw ValidationException::withMessages([
'options' => 'Please select at least two options.'
]);
}

The method efficiently returns early once it finds more than one matching item, making it performant even with large collections.

Pull Request: #58312

Gate Authorization with Enum Support

Laravel 12.45.2 enhances the Gate facade's has() method to accept UnitEnum instances, not just strings or BackedEnum types. This allows for more type-safe authorization code when checking if abilities are defined.

Previously, you could only check for ability existence using strings:

if (Gate::has('view-dashboard')) {
// Ability is defined
}

Now you can use PHP enums for type-safe ability checking:

enum Abilities {
case VIEW_DASHBOARD;
case EDIT_POST;
case DELETE_USER;
}
 
Gate::define(Abilities::VIEW_DASHBOARD, fn($user) => $user->isAdmin());
 
if (Gate::has(Abilities::VIEW_DASHBOARD)) {
// Type-safe ability check - works with UnitEnum!
}

This also works seamlessly with BackedEnum types:

enum Permission: string {
case ViewDashboard = 'view-dashboard';
case EditPost = 'edit-post';
}
 
if (Gate::has(Permission::ViewDashboard)) {
// Ability existence check with backed enum
}

This enhancement is particularly useful for dynamically registering permissions and conditional feature registration:

foreach (Permission::cases() as $permission) {
if (! Gate::has($permission)) {
Gate::define($permission, PermissionPolicy::class);
}
}

Pull Request: #58310

Miscellaneous Fixes and Improvements

Laravel 12.45.1, 12.45.2, and 12.46.0 also include several important bug fixes and improvements:

Version 12.46.0:

  • Fixed phpdoc of Container::buildSelfBuildingInstance() to prevent Psalm errors (#58314)
  • Fixed table prefix not being applied when cloning database connections (#58288)
  • Added MySQL DDL locking options to MySQL grammar for better table locking control (#58293)

Version 12.45.2:

  • Fixed Validator::appendRules() when using pipe-separated rule strings (#58304)
  • Fixed calling toArray() on AnonymousResourceCollection to properly return an array of resources (#58302)

Version 12.45.1:

  • Fixed ResourceCollection usage when used with a plain array instead of Model collection (#58299)

Upgrade Notes

These releases are backward compatible and do not require any code changes. Simply update your Laravel framework dependency to the latest version:

composer update laravel/framework

References

Paul Redmond photo

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

Sponsored

serpapi logo
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi

The latest

View all →
A simple form builder that stays out of your way image

A simple form builder that stays out of your way

Read article
Laravel AI: Trace Agent Runs With Lifecycle Events image

Laravel AI: Trace Agent Runs With Lifecycle Events

Read article
Laravel AI: Get Raw HTTP Responses and Rate Limits image

Laravel AI: Get Raw HTTP Responses and Rate Limits

Read article
Agent Run Observability in Laravel AI SDK 0.11 image

Agent Run Observability in Laravel AI SDK 0.11

Read article
Debounced Queued Event Listeners in Laravel image

Debounced Queued Event Listeners in Laravel

Read article
Statamic Mailables Viewer Previews Laravel Emails in the Control Panel image

Statamic Mailables Viewer Previews Laravel Emails in the Control Panel

Read article