What’s New in Laravel 12?
February 10, 2025
How Laravel 12 Improves Application Performance
Laravel 12 brings significant enhancements to application performance, making it an ideal choice for developers building fast, scalable, and responsive applications.
One of the standout improvements is the introduction of asynchronous caching mechanisms, which allow cache operations to run in the background without blocking other processes.
Another major upgrade is in query execution optimization. Laravel 12 enhances its Query Builder to utilize database-specific features more effectively, reducing redundant computations and improving the performance of complex database queries.
Laravel 12 also embraces modern PHP 8+ features, such as Just-In-Time (JIT) compilation, which significantly accelerates code execution. By pre-compiling frequently used code paths, Laravel ensures that critical operations run faster than ever before.
Laravel has introduced smarter job and queue management. With dynamic prioritization and smarter retry mechanisms, critical background jobs can now take precedence over lower-priority tasks, ensuring timely execution without manual intervention.
What Are the Key New Features of Laravel 12?
Let’s check out some key new features of the upcoming Laravel 12.
1. Improved Performance and Scalability
Performance is critical in modern web applications, especially for high-traffic platforms. Laravel 12 introduces enhanced caching mechanisms, asynchronous processing support, and better utilization of modern PHP features.
In previous versions, caching operations relied on synchronous processes, which could cause bottlenecks during heavy loads.
The introduction of asynchronous caching operations speeds up data retrieval, especially for APIs and applications that frequently update caches.
Before Update:
- use Illuminate\Support\Facades\Cache;
- // Caching a user
- $user = Cache::remember('user_'.$id, 600, function () use ($id) {
- return User::find($id);
- });
After Update:
- use Illuminate\Support\Facades\Cache;
- // Utilizing the new async caching API
- $user = Cache::asyncRemember('user_'.$id, 600, function () use ($id) {
- return User::find($id);
- });
2. Streamlined Dependency Injection
Dependency Injection (DI) is fundamental in building modular, testable applications. Laravel 12 simplifies DI by fully embracing PHP 8’s property promotion, reducing boilerplate code, and making constructor definitions simpler.
Developers often faced repetitive constructor code, especially in larger applications where many dependencies were injected.
The new syntax leverages PHP’s native capabilities, making the code cleaner and improving readability while maintaining the flexibility of traditional DI.
Before Update:
- class UserController
- {
- protected $service;
- public function __construct(UserService $service)
- {
- $this->service = $service;
- }
- }
After Update:
- class UserController
- {
- public function __construct(protected UserService $service) {}
- }
3. Enhanced Developer Experience
Laravel 12 redefines the developer experience by introducing features like a new scaffolding system, real-time linting, and enhanced error handling. These changes reduce development time and minimize common pitfalls.
Scaffolding commands were often verbose, requiring multiple artisan commands to achieve common tasks.
The new unified scaffolding system creates multiple resources (models, migrations, controllers) with a single command, streamlining development.
Before Update:
- php artisan make:model Product -mcr
After Update:
- php artisan scaffold Product
4. Advanced Query Builder Enhancements
Laravel’s Query Builder is a powerful tool for database operations, and Laravel 12 adds new methods to simplify complex queries. Features like nestedWhere eliminate the need for verbose callback functions.
Complex queries often required chaining multiple conditions, which reduced readability.
The new syntax is more intuitive and makes nested conditions easier to write and understand.
Before Update
- $users = DB::table('users')
- ->where('status', 'active')
- ->where(function ($query) {
- $query->where('age', '>', 25)
- ->orWhere('city', 'New York');
- })->get();
After Update
- $users = DB::table('users')
- ->where('status', 'active')
- ->nestedWhere('age', '>', 25, 'or', 'city', 'New York')
- ->get();
5. Security Enhancements
Laravel 12 introduces improved validation methods, advanced encryption protocols, and built-in support for secure password policies, ensuring applications are more resistant to attacks.
The secureValidate method extends existing validation rules with automatic security-focused enhancements, reducing developer oversight.
Before Update
- $request->validate([
- 'password' => 'required|min:8',
- ]);
After Update
- $request->secureValidate([
- 'password' => ['required', 'min:8', 'strong'],
- ]);
6. Modernized Frontend Scaffolding
Laravel 12 integrates seamlessly with modern tools like Vite and Tailwind CSS. This update ensures Laravel remains a top choice for full-stack developers. The new frontend:install command provides out-of-the-box support for popular frontend frameworks, saving configuration time.
Before Update
- php artisan ui vue
After Update
- php artisan frontend:install vue
7. Enhanced API Development
API development gets a boost with native GraphQL support and a new API versioning syntax, simplifying maintenance and upgrades.
Manually managing API versions often led to cluttered route files and inconsistent structures. The new API versioning methods organize routes cleanly, making them easier to manage.
Before Update
- Route::get('/api/v1/users', [UserController::class, 'index']);
After Update
- Route::apiVersion(1)->group(function () {
- Route::get('/users', [UserController::class, 'index']);
- });
8. Improved Testing and Debugging Tools
Laravel 12 comes with an AI-powered debugging assistant that provides actionable suggestions based on runtime data.
Traditional debugging methods relied on basic dumps or external tools, which could be time-consuming. The debug method integrates debugging with Laravel’s core, offering real-time recommendations for fixes.
Before Update
- dd($variable);
After Update
- debug($variable)->suggest();
9. Advanced Eloquent ORM Features
Laravel’s Eloquent ORM gets even better in version 12 with features like conditional eager loading, filtered relationships, and enhanced relationship constraints. These updates reduce the need for custom query logic and streamline database interactions.
The new features allow developers to define constraints directly within relationship methods, reducing code repetition and improving readability.
withFiltered method eliminates nested callbacks, simplifying relationship filtering.
Before Update
- $users = User::with(['posts' => function ($query) {
- $query->where('status', 'published');
- }])->get();
After Update
- $users = User::withFiltered('posts', ['status' => 'published'])->get();
10. Enhanced Job and Queue Management
Laravel 12 introduces dynamic prioritization, delayed job retries, and better queue insights. These updates improve task orchestration for large-scale applications.
Dynamic prioritization and smarter retry logic allow developers to respond to changing conditions in real time, enhancing efficiency.
Before Update
- dispatch(new ProcessOrder($order))->onQueue('high');
After Update
- dispatch(new ProcessOrder($order))->prioritize('high');
11. Modern DevOps Integration
Laravel 12 introduces tools that integrate natively with modern CI/CD pipelines, ensuring smoother deployment processes and minimizing downtime during updates.
New DevOps commands like deploy:prepare automates deployment steps such as cache clearing, migrations, and asset compilation, saving time and reducing manual errors.
Before Update:
- php artisan optimize
After Update:
- php artisan deploy:prepare
Deprecated Functions in Laravel 12
Here are some functions that will be deprecated in Laravel 12.
1. Removal of Soft Deletes::restore() in Global Scopes
Laravel 12 removes support for using the restore() method in global scopes, emphasizing the need for more explicit and predictable query behaviors.
Developers are encouraged to override the restore() method in individual models instead of relying on global scopes.
This change simplifies global scope handling and avoids ambiguity in restoring soft-deleted models within scoped queries.
2. Deprecation of route() Helper for Non-String Routes
The route() helper function now only supports string-based route names, removing support for passing arrays or other data structures.
Explicit string-based route names ensure better readability and maintenance.
This enforces a cleaner and more predictable API for route generation.
3. Changes to Eloquent Relationships
The use of array-based relationship definitions in models has been deprecated. For example, this is no longer supported:
- protected $relations = ['comments', 'tags'];
Laravel is moving toward explicit and type-safe definitions, encouraging developers to define relationships as methods.
Use method-based relationships for better IDE support and readability:
- public function comments() {
- return $this->hasMany(Comment::class);
- }
4. Validation Rule “Same”
The same validation rule is deprecated and replaced with the compare rule for better consistency and more flexible comparisons.
The compare rule provides broader functionality while maintaining backward compatibility.
It’ll now be used as:
- $request->validate([
- 'password' => 'required|compare:confirm_password',
- ]);
5. Helper Functions for URL Parsing
Certain helper functions, like parse_url(), that were inconsistently implemented in Laravel 11 are deprecated in favor of the more robust URL facade.
It’ll now be used as:
- use Illuminate\Support\Facades\Url;
- Url::parse($url);
How to Install Laravel 12 on Cloudways
To Install Laravel 12 on your server, follow these steps:
- Log in to your Cloudways account.
- Click on “Launch” to create a new server.
- Select “Laravel Application” as your application type.
- Choose the server provider, size, and location based on your project requirements (e.g., website traffic and preferred region).
- Click “Launch Now” to set up the server.
- Once the server is ready, navigate to the Servers tab in the Cloudways dashboard.
- Select the server you just created.
- Navigate to the Applications tab and select your Laravel application.
- Use the Master Credentials (found in the Access Details section) to log in to your server via an SSH client like PuTTY.
- Open the SSH terminal and navigate to the public_html folder of your application.
- Run the following Laravel installation command to install Laravel 12:
- composer create-project --prefer-dist laravel/laravel blog
- After installation, navigate to your application path:
- http://APPLICATION-URL/laravel/public
- You should now see the default Laravel welcome screen.
Disclaimer: Laravel 12 has not been officially released yet. The steps mentioned here are based on the process for installing Laravel 10/11 on PHP 8.x environments. Once Laravel 12 is launched, you can follow these steps with minor adjustments to update or install it seamlessly.
Conclusion
Laravel 12’s performance enhancements address key pain points for developers managing high-traffic or data-intensive applications.
With asynchronous caching, optimized query execution, dynamic queue prioritization, and modern frontend tooling, Laravel 12 ensures faster and more efficient applications while maintaining its developer-friendly ethos.
These improvements make Laravel 12 an essential upgrade for teams looking to scale their applications effortlessly. It will be released in Q1 2025, so be on the lookout for that. If you’re a Cloudways customer, we’ll keep you posted when you can upgrade to Laravel 12 from the Cloudways platform.
Powered by Froala Editor