Laravel 12 Installation & New Features Overview

By Hardik Savani February 25, 2025 Category : Laravel

In this post, I will show you laravel 12 new features and enhancement and let's review it together. still laravel 12 documents adding more features but right you can review it from github repo.

Installing Laravel 12

Laravel 12 is officially scheduled for release on February 24, 2025. To install the early version, use the following command:

composer create-project --prefer-dist laravel/laravel hello-world

you will see the new brand home page of laravel 12:

New Features in Laravel 12

Let's see the one by one features:

1. Introduction of nestedWhere() for Complex Queries

Laravel 12 introduces the `nestedWhere()` method, simplifying complex query structures.

Before:

$products = Product::select("*")
            ->where("status", 1)
            ->where(function($query) {
                $query->where("price", "orWhere("discount", ">", 25);
            })
            ->get();

After:

$products = Product::select("*")
            ->where("status", 1)
            ->nestedWhere("price", "", 25)
            ->get();

2. Upgrade to Carbon 3

Laravel 12 replaces Carbon 2 with Carbon 3, introducing improved date and time handling.

3. Str::is() Now Matches Multiline Strings

The `Str::is()` helper (and `str()->is()`) now correctly matches multiline strings using the regex `s` modifier. Previously, wildcard patterns (`*`) did not match newline characters.

Str::is('*', $multilineString); // false
Str::is('first*', $multilineString); // false
Str::is("first\n*", $multilineString); // false
Str::is("first\nsecond\n*", $multilineString); // true

4. Enhanced Security with secureValidate()

Laravel 12 introduces `secureValidate()` for stronger password validation.

Before:

$request->validate(['password' => 'required|min:8']);

After:

$request->secureValidate(['password' => 'required|min:8|strong']);

5. apiVersion() for API Development

Laravel 12 natively supports GraphQL and introduces `apiVersion()` for improved API versioning.

Before:

Route::get("v1/users", [UserController::class, "index"]);

After:

Route::apiVersion(1)->group(function() {
    Route::get("users", [UserController::class, "index"]);
});

6. Enhanced Debugging Tools

Laravel 12 introduces AI-powered debugging assistance, featuring a new `debug()` method to diagnose issues and suggest solutions in real time.

debug($variable)->suggest();

7. Concurrency Result Index Mapping

When using `Concurrency::run()` with an associative array, the results now maintain their associated keys:

$result = Concurrency::run([
    'task-1' => fn () => 1 + 1,
    'task-2' => fn () => 2 + 2,
]);

// ['task-1' => 2, 'task-2' => 4]

8. Image Validation Now Excludes SVGs by Default

The `image` validation rule no longer allows SVG images by default. To include SVGs, explicitly allow them:

'photo' => 'required|image:allow_svg'

Output:

I hope it can help you...

Shares