What's New in Laravel 9: New Features of Laravel 9
Tags: laravel, webdev, beginners, tutorial
Published: 2022-01-17 09:14:41

Laravel has been one of the most popular PHP frameworks for many years. It’s elegant, scalable, has become one of the de facto frameworks for developers and companies working with PHP. Now, Laravel 9 is on the way with a ton of new features.

In the past, new releases have been happening every six months, resulting in a fair amount of questions, harsh comments, and confusion about Laravel’s new release process. With the release of Laravel 9, the framework has moved to a 12-month major release cycle and will release in January 2022.

This blog explores Laravel 9’s key features. On top of that, we’ll also detail how to upgrade to Laravel 9 and start developing web apps.

## Table of Contents

1. What is Laravel?
2. Key Features of Laravel
3. What To Expect With Laravel 9
4. New Features in Laravel 9
5. How To Install Laravel 9

## What is Laravel?
Laravel is an open-source PHP web application framework with expressive, elegant syntax. It is an MVC framework for building simple to complex web applications using the PHP programming language. 

Laravel strictly follows the MVC (Model-View-Controller) architectural pattern. It is known for its beautiful and elegant syntax as a web framework.

## Key Features of Laravel
Some of the main features of Laravel are:

- Eloquent ORM
- Query builder
- Reverse Routing
- Restful Controllers
- Migrations
- Database Seeding
- Unit Testing
- Homestead
- Source code hosted on GitHub and licensed under MIT License.
- Most Starred PHP Framework for custom software development on Github.
- Its ability to use all of the new features of PHP sets it apart.
- Friendly online community
- Detailed documentation
- Security

## What To Expect With Laravel 9

Laravel 9 is the first Long Term Support (LTS) released in a 12-month release cycle and was initially scheduled to be released by September 2021; however. The Laravel team decided to push it to January 2022.

This release schedule is due to these reasons outlined below: with these reasons below, the release date was pushed forward.

1. Laravel as a framework relies on different community-driven and 9 Symfony libraries, and Symfony is planning to release v6.0 by November 2021, making the Laravel team delay the release of Laravel v9.
2. To update or upgrade the entire Laravel framework to the latest version of Symfony will take a while and also lots of testing and monitoring against any breaking changes before releasing it to the public.
3. Finally, delaying the release of Laravel 9 till January 2022 will better position the Laravel team to release subsequent LTS yearly which gives the Laravel team 2 months after Symfony’s releases.
Now that we know the reasons for the changes, let’s explore the new Laravel v9 before it is released by January 2022.

## New Features in Laravel 9
Below is the newest features and improvement that we should expect in the Laravel v9 by January 2022:
### Minimum PHP Requirement
Since Laravel 9 will require Symfony 6.0 and it has a minimum requirement of PHP 8 that means Laravel 9 will carry this same restriction.
### New Design for routes:list
The routes:list the command has been included in Laravel for a long time now, and one issue that sometimes arises is if you have huge and complex routes defined it can get messy trying to view them in the console. 

![What's New in Laravel 9: New Features of Laravel 9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc36df4ej7zicdcynnl5.png)
### Anonymous stub migration
With Laravel 9, you can set anonymous stub migration as the default behavior while running the popular migration command. This valuable feature came out with the release of Laravel 8.37, which aimed to solve the GITHUB issue.

What is this issue? When you create a database from scratch, numerous migrations with the same class name can create problems. With the anonymous stub migration feature, issues related to class name collisions are eradicated instantly.

Since the release of Laravel 8.37, the frameworks support anonymous class migration files. With Laravel 9, the same would become the default behavior when Laravel 9 will be launched and when you execute php artisan make:migration.
```
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table)
        {
            $table->string('first_name')->nullable();
        });
    }
};
```
### New Query Builder Interface
Appreciations to Chris Morrell, Laravel 9 will highlight a new Query Builder Interface, and you can view this merged PR for all the details.

For developers who depend on sort insights for static analysis, refactoring, or code completion in their IDE, the need for a shared interface or legacy between Query\Builder, Eloquent\Builder, and Eloquent\Relation can be much complex.
```
return Model::query()
    ->whereNotExists(function($query) {
        // $query is a Query\Builder
    })
    ->whereHas('relation', function($query) {
        // $query is an Eloquent\Builder
    })
    ->with('relation', function($query) {
        // $query is an Eloquent\Relation
    });
```
This version added the new Illuminate\Contracts\Database\QueryBuilder interface, as well as the Illuminate\Database\Eloquent\Concerns\DecoratesQueryBuilder a trait that will implement the interface in place of the __call magic method.

### PHP 8 String Functions
Since PHP 8 will be the least, Tom Schlick acknowledged a PR to move to using str_contains(), str_starts_with() and str_ends_with() functions internally in the \Illuminate\Support\Str class.

Laravel 9’s features and improvements listed above are a sneak peek at what is to come. It’ll most definitely bring lots of bug fixes, features, and, of course, many breaking changes.

### From Swift Mailer to Symfony Mailer
Symfony deprecated Swift Mailer and Laravel 9 makes the change to use Symfony Mailer for mail transport. There are a few breaking changes as a result, you can see the PR for more information.

## How To Install Laravel 9
For development and testing purposes, you can easily install and run Laravel 9 on your local device. As stated above, Laravel supports PHP v8 engine only. Check your current PHP version before installation and testing. To simplify matters, get rid of the existing version and begin a fresh install.

With the command mentioned above, you can create a new Laravel project while naming it laravel-9-dev, using the latest Laravel 9 which is still under development. To install, run:
```
composer create-project --prefer-dist laravel/laravel laravel-9-dev test-laravel9
```
or, if you have installed the Laravel Installer as a global composer dependency:
```
laravel new laravel-9-dev test-laravel9
```
After you finish installing Laravel 9, enter the new directory, and run the artisan command to check the current version.
```
cd dev-laravel9
php artisan --version
```
Thank you for reading this blog.