Laravel 9 Tutorial: Laravel 9 new features
Tags: webdev, beginners, javascript, laravel
Published: 2021-07-27 09:14:28

---
title: Laravel 9 Tutorial: Laravel 9 new features
published: true
date: 2021-07-20 20:37:03 UTC
tags: webdev,beginners,javascript,laravel
canonical_url: https://medium.com/backenders-club/laravel-9-tutorial-laravel-9-new-features-3d1af79edad7
---

With the different features of Laravel, it is the most favorite framework amongst developers and companies using the PHP programming language. This adoption is due to the elegancy and scalability nature of the framework.

![](https://cdn-images-1.medium.com/max/1024/0*6I6xyRTzXutpwOYh.png)

With the Laravel 9 release, the Laravel team switches from the traditional 6-month release cycle to a 12-month release cycle using the [Semantic Versioning(Semver)](https://semver.org/) approach.

The initial schedule of the Laravel 9 release was supposed to be September 2021, following the traditional approach. Still, the release date changed to January 2022 as stated by the creator and with a few valid reasons, as noted below.

In this article, we will discuss in detail Laravel 9 and the best features of Laravel. We will also detail how to update or upgrade to Laravel 9 and install and start building an app with the new Laravel 9.

_Before_ you dive in, _if you’re a_ [_backend developer_](https://masteringbackend.solomoneseme.com/posts/backend-development-the-ultimate-guide/) _or looking at delving into this career path, join other developers to receive daily articles on backend development that will boost your productivity._

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

If you haven’t used Laravel, you can read through the [ultimate guide to Laravel](https://masteringbackend.com/posts/laravel-framework-the-ultimate-guide) and peek at [Laravel 8 new features](https://masteringbackend.com/posts/laravel-8-new-features) to get started.

### Laravel 9 and What to Expect

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 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.

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

Laravel 9 requires the newest version of PHP 8, PHPUnit 9, and a few other requirements specified in the future.

The PHP 8 requirement is because Laravel 9 is solely dependant on Symfony’s latest v6.0 release, which depends on PHP 8.

You can explore [what is new in PHP 8](https://kinsta.com/blog/php-8/#php-8-improvements-and-new-features) and the different [PHP versions benchmarks](https://kinsta.com/blog/php-benchmarks/) to grasp the improvements and features of PHP 8 from Just-In-Time compiler (JIT) to constructor property promotion.

### Anonymous Stub Migration

The anonymous stub migration released in Laravel version 8.37 to solve this [Github Issue](https://github.com/laravel/framework/issues/5899) will be the default behavior of the newest Laravel 9.

Anonymous Stub Migration eliminates the collision of migration class names. The collision happens when multiple migrations have the same class name, it’ll cause issues when trying to recreate the database from scratch.

Here is the sample code snippet of how the new migration file will look like:

```
<?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(); 
   }); 
 } 

};
```

This code snippet uses Schema::table instead of the traditional Schema::create() method.

### New Query Builder Interface

Type hinting is crucial as developers highly rely on refactoring, static analysis, and code completion in their IDEs.

With Laravel 9, developers can now enjoy a shared interface or inheritance between Query\Builder, Eloquent\Builder and Eloquent\Relation with the new Query Builder Interface.

You can read through this for all the details:

```
<?php 

  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 
     });
```

Laravel v9 added the new Illuminate\Contracts\Database\QueryBuilder interface and Illuminate\Database\Eloquent\Concerns\DecoratesQueryBuilder trait that will implement the interface in place of the existing \_\_call magic method.

### PHP 8 String Functions

Laravel v9 requires PHP v8, so the Laravel team agreed to merge a [PR](https://github.com/laravel/framework/pull/38011) to use the newest PHP 8 String functions.

The suggested functions include str\_contains(), str\_starts\_with() , and str\_ends\_with() to be used internally in the \Illuminate\Support\Str class.

### And More

Laravel v9 is still in active development and will introduce more future improvements and features that we have not listed yet in this article. Laravel v9 will most definitely come with lots of significant changes, bug fixes, features, and of course, many breaking changes.

Do well to subscribe to our newsletter to stay ahead.

### How to install Laravel 9

If you’re like us, we love to explore the newest technologies before being open to the public. You can start playing with the upcoming Laravel v9 for development and testing purposes. You can easily install and run it on your local machine following the guide below.

In addition, Laravel 9 supports PHP version 8. Make sure to check and upgrade your [PHP version](https://kinsta.com/knowledgebase/devkinsta/php-versions/) to use Laravel 9 before next January 2022.

To install Laravel 9, the first method is the Laravel global CLI which creates a new Laravel project from the branch specified. In this case, we will choose to create the new Laravel project from the dev branch.

Run the following command below in your directory to create a new Laravel 9 project. Make sure to have [Laravel CLI](https://laravel.com/docs/8.x/installation#the-laravel-installer) installed globally.

```
laravel new laravel-9-todo-app --dev
```

Next, to install Laravel 9 using composer, run the following command to install Laravel v9:

```
composer create-project --prefer-dist laravel/laravel laravel-9-todo-app dev-develop
```

The composer command will create a new Laravel project with project name as _laravel-9-todo-app_, using the dev-develop will result in the latest Laravel 9.

Now that we have Laravel 9 installed, you can navigate to the new laravel-9-todo-app directory and run the following artisan command to check the version:

```
cd laravel-9-dev 
php artisan --version 

//Laravel Framework 9.x-dev
```

Now that you have Laravel 9 installed, you should read the [ultimate guide to Laravel](https://masteringbackend.com/posts/laravel-framework-the-ultimate-guide/) to learn how to build scalable Laravel applications.

### Conclusion

This article detailed the features of Laravel 9 and what to expect in future releases. It also explored how to update or upgrade to Laravel 9 and install and start building an app with the new Laravel 9.

_Originally published at_ [_https://masteringbackend.com_](https://masteringbackend.com/posts/laravel-9-tutorial-laravel-9-new-features) _on July 20, 2021._

* * *