Laravel 12.42 Highlights: HTTP Client Attributes, Enum Translator, Schema Index Checks

Laravel 12.42.0 introduces a new HTTP client withAttributes method, enum support in Translator replacements, and schema builder helpers whenTableHasIndex/whenTableDoesntHaveIndex, alongside numerous other improvements and bug fixes detailed in the release notes.

21CTO
21CTO
21CTO
Laravel 12.42 Highlights: HTTP Client Attributes, Enum Translator, Schema Index Checks

Laravel Framework 12.42.0 – Key Changes

HTTP client request attributes

Added withAttributes() to PendingRequest. Allows setting custom attributes that can be retrieved via attributes() on the response.

$response = Http::withAttributes(['name' => 'first'])
    ->get('https://example.com/test');

$attributes = $response->attributes(); // ['name' => 'first']

Enum support in Translator replacements

The Translator now accepts PHP enum values when performing placeholder replacements, enabling type‑safe translations.

$t = new Translator($loader, 'en');
echo $t->get('string_backed_enum', ['month' => Month::February]);
// Output: "Laravel 12 was released in February 2025"

Schema builder index helpers

Two new helpers whenTableHasIndex and whenTableDoesntHaveIndex simplify conditional index creation.

// Before
if (!Schema::hasIndex('product', 'name')) {
    Schema::table('product', function (Blueprint $table) {
        $table->index('name', 'index_name');
    });
}

// After
Schema::whenTableHasIndex('product', 'name', function (Blueprint $table) {
    $table->index('name', 'index_name');
});

// Specify index type
Schema::whenTableDoesntHaveIndex('product', 'name', function (Blueprint $table) {
    $table->index('name', 'index_name');
}, 'unique');

Other notable changes

Context::scope()

now returns a type (PR #58012).

CarbonInterval duration helpers accept floating‑point values (PR #58006).

Added commandFileFinder with test‑file exclusion (PR #58017).

Queue worker respects --quiet and --silent flags (PR #58024).

Container dependency support added (PR #58026).

Fixed autoload issue for StringableObjectStub (PR #58030).

Removed deprecated optional() calls (PR #58027).

Added newRequest() to request pools and batches (PR #58038).

Improved listener documentation and added unit tests for query shapes (PR #58040).

Pre‑migration hook for parallel test databases (PR #58011).

Support for PHPUnit 12.5 (PR #58042).

Enum support in Translator replacements (PR #58048).

Fixed concurrency issues with PendingRequest@pool() and batch() (PR #57973).

Standardised queue command option descriptions (PR #58058).

Added LICENSE, PR auto‑close, and .gitattributes configuration (PR #58055).

New PendingRequest@withRequestContext() method (PR #58054).

Full release notes: https://github.com/laravel/framework/releases/tag/v12.42.0

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

backendenumPHPLaravelHTTP clientRelease NotesSchema Builder
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.