What’s new in Laravel 9?
Laravel 9, released on February 8, 2022, introduced several new features, improvements, and refinements aimed at enhancing developer productivity and application performance. Here's an overview of what's new in Laravel 9:
1. Minimum Requirements
- PHP 8.0+: Laravel 9 requires PHP 8.0 or higher, leveraging the latest features and performance improvements of the language.
- Symfony 6.x: The framework uses Symfony 6 components, providing enhanced performance and additional capabilities.
2. Improved Route Listing
Laravel 9 introduces a new route:list
output format, making it easier to view route details like methods, URIs, names, and middleware.
The table now includes colors and highlights for better readability.
3. Anonymous Stub Migrations
By default, migrations now use anonymous classes, preventing migration name collisions.
Before:
Now:
4. New Query Builder Interface
The new type-safe query builder interface improves static analysis and code completion in IDEs, making it easier to catch errors during development.
5. Laravel Breeze API
Laravel Breeze, the lightweight authentication scaffolding, now includes an API mode. This addition simplifies the creation of APIs with authentication.
6. Full-Text Search Support
Laravel 9 adds support for MySQL and PostgreSQL full-text indexing and searching capabilities. Developers can now perform advanced search queries using whereFullText()
and orWhereFullText()
.
7. Improved Eloquent Accessors and Mutators
Laravel 9 provides a cleaner way to define Eloquent accessors and mutators using PHP 8's attribute
method.
Example:
8. Bootstrap 5 Pagination Views
The pagination views now use Bootstrap 5 by default, aligning with modern UI standards.
9. Flysystem 3.x Integration
Laravel 9 integrates Flysystem 3.x, which improves file storage capabilities, including better handling of complex file systems and customizable storage adapters.
10. New --model
Option for Artisan Commands
Laravel 9 enhances make:controller
and make:resource
Artisan commands by allowing you to generate a model alongside the controller.
Example:
11. Improved Testing Features
Laravel 9 provides new test methods and enhancements:
assertDatabaseCount()
: Asserts the number of records in a database table.assertModelExists()
andassertModelMissing()
: Asserts the existence or non-existence of a model in the database.
12. Symfony Mailer
Laravel 9 replaces SwiftMailer with Symfony Mailer, providing better email handling with extended capabilities.
13. Optional Bootstrap Ignition
Ignition, the Laravel error page handler, now allows optional configuration to control error reporting behavior.
14. Support for PHP 8 Features
Laravel 9 leverages PHP 8 features, such as attributes, union types, and match expressions, for cleaner and more expressive code.
Why Upgrade to Laravel 9?
Laravel 9 focuses on developer convenience, modern PHP standards, and better performance, making it a compelling choice for both new and existing applications. If you're upgrading from an earlier version, refer to the upgrade guide.