Introduction
Laravel is a PHP framework for web development. It was created by Taylor Otwell and was initially released as an open-source project in June 2011.
Since its initial release, Laravel has grown to become one of the most popular PHP web frameworks in the world.
Today (February 9, 2022), Laravel 9 got released, and here are the main changes!
PHP requirements
As of Laravel 9, the minimum PHP version required is PHP 8.0. If you are using PHP 7.4 or earlier, you will need to update your PHP version.
New Mailer library
Old versions of Laravel used the SwiftMailer library for sending emails, however, this is no longer the case with Laravel 9, and the SwiftMailer library has been replaced with the Symfony Mailer.
Flysystem updates
Laravel 9 now ships with a new Flysystem version 3.x. The Flysystem powers the Laravel filesystem and you can with it using the Storage
facade.
Improved route:list
output
The route:list
command now outputs a more readable and consistent output.
Full-text indexes
When using Postgres or MySQL, you can now add a column definition to your database table to create a full text index:
$table->text('details')->fullText();
Enum Eloquemtn Attribute Casting
Eloquent now supports casting enum attributes to their string values. To do that you can specify the $casts
property on your model:
use App\Enums\ServerStatus;
public $casts = [
'status' => ServerStatus::class,
];
To take advantage of the new enum attribute casting, you need to have PHP 8.1 or later installed.
Forced Scoping of route bindings
You can now force the scoping of a second model in your route bindings. For example, if you have a route that accepts a user
and post
model:
Route::get('/{user}/{post:slug}', function (User $user, Post $post) {
return $post;
});
Controller route groups
You can now group routes in a controller using the Route::controller
method:
use App\Http\Controllers\OrderController;
Route::controller(OrderController::class)->group(function () {
Route::get('/orders/{id}', 'show');
Route::post('/orders', 'store');
});
Inline Blade Templates
With Laravel 9, you can now use inline blade templates to transform a raw Blade template into a valid HTML:
use Illuminate\Support\Facades\Blade;
return Blade::render('Hello, {{ $name }}', ['name' => 'Julian Bashir']);
New Ignition Extension Page
The ignition extension page has been redesigned and improved:
New helper functions
There are two new helper functions:
- The
str
function:
$string = str('Dev')->append('Dojo');
// 'DevDojo'
- The
to_route
function:
return to_route('users.show', ['user' => 1]);
This generates a redirect response to the specified route. You can also specify the status code:
return to_route('users.show', ['user' => 1], 301);
Guzzle default timeout
With Laravel 9, by default, Guzzle will wait for a response for a maximum of 30 seconds before timing out.
This can easily be overridden by setting the timeout
option on the client:
Http::timeout(60)->get('https://example.com');
Video
To learn Laravel 9, you can watch this video:
Laracon
Today is also the day of Laracon online! You can watch it for free as described here:
Conclusion
For more information about Laravel 9, please visit the official documentation:
If you are planning to upgrade to Laravel 9, you can read the official upgrade guide.
What is your opinion about Laravel 9, and what version of Laravel are you using?
Comments (0)