# What is new in Laravel 9

By Bobby Iliev, 2022-02-09. https://bobbyiliev.com/post/what-is-new-in-laravel-9/

## 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!

<iframe src="https://giphy.com/embed/mPOGx4hJtOWSA" width="480" height="258" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/despicable-me-minions-cute-mPOGx4hJtOWSA">via GIPHY</a></p>

## 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:

```php
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:

```php
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 Ignition Extension Page](https://imgur.com/aMetoAU.png)

## New helper functions

There are two new helper functions:

- The `str` function:

```php
$string = str('Dev')->append('Dojo');
// 'DevDojo'
```

- The `to_route` function:

```php
return to_route('users.show', ['user' => 1]);
```

This generates a redirect response to the specified route. You can also specify the status code:

```php
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. To test how your app handles that, you can [create a connection timeout on purpose](https://devops-daily.com/posts/how-to-artificially-create-connection-timeout-error).

This can easily be overridden by setting the `timeout` option on the client:

```php
Http::timeout(60)->get('https://example.com');
```

## Video

To learn Laravel 9, you can watch this video:

<iframe width="100%" height="399" src="https://www.youtube.com/embed/MnSzUX7kU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

## Laracon

Today is also the day of Laracon online! You can watch it for free as described here:

- [Laracon Online](https://devdojo.com/tnylea/laracon-online-2022)

## Conclusion

For more information about Laravel 9, please visit the official documentation:

- [Laravel 9 Documentation](https://laravel.com/docs/9.x)

If you are planning to upgrade to Laravel 9, you can read the [official upgrade guide](https://laravel.com/docs/9.x/upgrade).

What is your opinion about Laravel 9, and what version of Laravel are you using?
