What’s New in Laravel 9 ?

What is Laravel?

Laravel is an open-source PHP web application framework known for its elegant syntax. It’s an MVC framework for building simple to complex web applications using the PHP programming language, and it strictly follows the MVC (model–view–controller) architectural pattern.

Features of Laravel.

1. Template Engine:

Laravel framework is highly acknowledged for its built-in lightweight templates which can be used to create wonderful layouts using dynamic content seeding. In addition to this, it provides multiple widgets incorporating CSS and JS code with robust structures. Laravel templates are innovatively designed to create simple as well as complex layouts with distinctive sections.

2. MVC Architecture Support:

Laravel supports the MVC architecture pattern which ensures separate business logic and presentation layers. MVC pattern of Laravel has a lot of built-in functions, improves application performance, and increases security as well as scalability.

3. Eloquent ORM (Object Relational Mapping):

Laravel offers Eloquent Object Relational Mapping (ORM) which includes a simple PHP Active Record implementation. This allows web application developers to write database queries with PHP syntax rather than writing SQL code. An ORM is relatively faster than other PHP frameworks.

4. Security:

Laravel framework offers very strong web application security. It uses hashed and salted password mechanisms so the password would never be saved as plain text in the database. It also uses the “Bcrypt Hashing Algorithm” for generating an encrypted password. Additionally, this PHP web development framework uses prepared SQL statements that prevent SQL injection attacks.

5. Artisan:

Laravel framework offers a built-in command-line tool called Artisan which helps to automate the majority of tedious repetitive programming tasks. These artisans can also be utilized to create the database structure, a skeleton code, and manage migration so it is a pretty easy-to-manage database system. In addition, it can generate basic MVC files through the command line and manage those assets as well as their respective configurations. Artisan even helps developers to create their own commands and use them as required.

6. Libraries & Modular:

Laravel comes with pre-installed Object-Oriented and Modular libraries which are not available in many other PHP Laravel frameworks. For example, an Authentication library that is easy-to-implement and has features such as checking active users, Bcrypt hashing, password reset, CSRF (Cross-site Request Forgery) protection, and encryption. Furthermore, this framework is divided into individual modules adopting modern PHP principles facilitating responsive and modular web application development.

 

 

What’s New in Laravel 9?

Scheduled to be released by September 2021, Laravel 9’s release was pushed to January 2022 (and later February 2022), making it the first long-term support (LTS) release to be introduced following the 12-month release cycle. This delay results from many reasons, which include but are not limited to the following:

  1. Laravel uses varieties of community-driven projects and about nine Symfony libraries. However, Symfony is planning the release of version 6.0 by November 2021. The delay will allow the Laravel team to incorporate this new version of Symfony as part of Laravel 9.
  2. The delay will afford the team time to monitor how Laravel interacts with the new version of Symfony for two months. It also gives them room to correct any breaking changes or bugs.
  3. Lastly, delaying Laravel 9 better positions the Laravel team for yearly future releases. After Symfony’s release, it will give the team two months of additional ramp-up time.

Laravel 9 new Features

1. Minimum PHP Requirement.

First and most importantly, Laravel 9 requires the latest PHP 8 and PHPUnit 8 for testing. That’s because Laravel 9 will be using the newest Symfony v6.0, which also requires PHP 8. PHP 8 has significant improvements, and features, from the JIT compile to constructor property promotion.

2. Anonymous Stub Migration

Laravel sets to make anonymous stub migration the default behavior when you run the popular migration command:

php artisan make:migration

The anonymous stub migration feature was first released in Laravel 8.37 to solve this Github issue. The issue is that multiple migrations with the same class name can cause problems when trying to recreate the database from scratch. The new stub migration feature eliminates migration class name collisions.

From Laravel 8.37, the framework now supports anonymous class migration files, and in Laravel 9, it will be the default behavior.

<?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('people', function (Blueprint $table)
        {
            $table->string('first_name')->nullable();
        });
    }
};
3. New Query Builder Interface

With the new Laravel 9, type hinting is highly reliable for refactoring, static analysis, and code completion in their IDEs. Due to the lack of shared interface or inheritance between Query\Builder, Eloquent\Builder, and Eloquent\Relation. Still, with Laravel 9, developers can now enjoy the new query builder interface for type hinting, refactoring, and static analysis.

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

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.

4. PHP 8 String Functions

Since Laravel 9 targets PHP 8, Laravel merged this PR, suggesting using the newest PHP 8 string functions.

These functions include the use of str_contains(), str_starts_with(), and str_ends_with() 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.

 

2 thoughts on “What’s New in Laravel 9 ?”

Leave a Comment

Scroll to Top