Google News
logo
Laravel - Interview Questions
What are the new features of Laravel 9?
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.
 
Anonymous Stub Migration : Laravel sets to make anonymous stub migration the default behavior when you run the popular migration command:
php artisan make:migration
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();
        });
    }
};

?>
 
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 trait that will implement the interface in place of the __call magic method.
 
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.
 
 
 
Advertisement