Laravel

What is the difference between Laravel 8 and Laravel 9

In this article I will guide you what is the difference between Laravel 8 an Laravel 9 along with I will also tell you what’s new in Laravel 8 and in the Laravel 9.

Let’s begin with what’s new in Laravel 9.

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. 

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();
        });
    }
};
        Schema::table('users', function (Blueprint $table)
        {
            $table->string('first_name')->nullable();
        });
    }
};

Features in Laravel 8

Let’s begin with what’s in Laravel 8.

I have noticed in the way that my Laravel project is rendering the route list in the terminal. It is no longer comma separating the middleware column, and if there is more than one middleware it will add it to a new blank row in the table underneath its parent route.

This may seem like a very trivial problem, however being relatively new to laravel and this being my first proper project I have been producing with it I am firstly concerned that there could be an issue with the laravel install somehow that may cause other issues elsewhere, and the more routes I add with various middleware, the table when displaying all routes is becoming rather difficult to interoperate, where this was not an issue before.

See below a screenshot of the route table filtered to show only a select number of the routes in my project in order to give you an idea of what I am seeing

Anonymous Migrations in Laravel

The Laravel team released Laravel 8.37 with anonymous migration support, which solves a GitHub issue with migration class name collisions. The core of the problem is that if multiple migrations have the same class name, it’ll cause issues when trying to recreate the database from scratch.

In Laravel 8.37, the framework can now work with anonymous class migration files. Here’s an example from the pull request tests:

 1use 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();
        });
    }
 
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('people', function (Blueprint $table) {
            $table->dropColumn('first_name');
        });
    }
};

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button