Laravel 12 Installation & New Features Overview
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'
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Implement Email Verification in Laravel?
- How to Get Http Hostname in Laravel?
- How to Drop Unique Constraint in Laravel Migration?
- Laravel Migration Change Datatype Int to Bigint Example
- Laravel Unique Validation with Condition Example
- Laravel Country List with Flags Example
- Laravel Google 2FA Authentication Tutorial Example
- How to use Carbon in Laravel Blade or Controller File?
- How to Add Two Factor Authentication with SMS in Laravel?
- Laravel Send SMS to Mobile with Nexmo Example