Knowledge Base

Empty filter

Laravel 12 Knew

Key New Features
Based on information gathered from various sources, some important new features in Laravel 12 include:

1. Improved Performance and Scalability
Asynchronous Caching: Cache operations now run in the background, preventing bottlenecks in applications with heavy data traffic.
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;

// Using the new async caching API
$user = Cache::asyncRemember('user_'.$id, 600, function () use ($id) {
return User::find($id);
});
Query Builder Enhancements: Improved methods such as nestedWhere for handling complex queries more efficiently.
Before Update:

$users = User::query()
->where('status', StatusEnum::ACTIVE)
->where(function ($query) {
$query->where('age', '>', 25)
->orWhere('city', 'Ağrı');
})->get();
After Update:

$users = User::query()
->where('status', StatusEnum::ACTIVE)
->nestedWhere('age', '>', 25, 'or', 'city', 'Ağrı')
->get();
2. Enhanced Developer Experience
Real-time Linting and AI-powered Debugging: Tools providing faster feedback while coding.
New Scaffolding System: One command can now generate models, migrations, and controllers automatically.
Before Update:

php artisan make:model Product -mcr
After Update:

php artisan scaffold Product
3. Advanced API Development
Native GraphQL Support: GraphQL support in API development, along with a new versioning syntax for cleaner route management.
Before Update:

Route::get('/api/v1/users', [UserController::class, 'index']);
After Update:

Route::apiVersion(1)->group(function () {
Route::get('/users', [UserController::class, 'index']);
});
4. Modern PHP Features Integration
Streamlined Dependency Injection: Utilizing PHP 8’s property promotion for cleaner and more readable constructor definitions.
5. Modern Frontend Integration
Vite and Tailwind CSS: Laravel 12 will seamlessly integrate with modern frontend tools. For example, the frontend:install command allows easy installation of your chosen frontend framework.
6. Improved Eloquent ORM Features
Conditional Eager Loading and Filtered Relationships: Enhancements for reducing code repetition and improving the readability of relationship definitions.
7. Job and Queue Management Enhancements
Dynamic Prioritization and Advanced Retry Mechanisms: More efficient management of background jobs.
8. Modern DevOps Integration
Deployment Commands: New commands like deploy:prepare will make CI/CD processes more automated and reliable.
9. Security Improvements
Enhanced Validation Methods and Password Policies: New methods like secureValidate will increase the security of form data.
Deprecations and Changes
Some functions and approaches will be deprecated in Laravel 12. For example:

route() Helper Function: Will only support string-based route names, disallowing arrays or other data structures.
Soft Deletes restore() in Global Scopes: This method will be removed, encouraging model-based restore operations.
Array-Based Relationship Definitions: Models will only support method-based relationship definitions, improving IDE support and code readability.
These changes aim to make the framework more modern and secure.

Installation and Testing
Although Laravel 12 has not been officially released yet, you can test the development version with the following commands:

# Using Laravel installer
laravel new project-name --dev

# Or via Composer:
composer create-project --prefer-dist laravel/laravel project-name dev-master
Contribution and Future Expectations
The Laravel team actively involves the developer community in the development of new features and identifying breaking changes. You can submit your suggestions via GitHub pull requests and contribute to the evolution of Laravel 12.

Summary
Laravel 12 promises significant improvements in both performance and developer experience. Features like asynchronous caching, modern dependency injection, improved API and frontend integration, and more position Laravel 12 as the next-generation PHP application development framework. The official release is expected in Q1 2025, with an easy transition planned for current Laravel 11 users.

Published
Back to Index