Closed3

Laravel 9.0 新機能 キャッチアップ

ohki_suguru.phpohki_suguru.php

概要

  1. PHP 8.0 が最低限必要
  2. Symfony6系を利用している
  3. 次のLTSとなる
version release date
Laravel 9.0 2022年1月(January 2022)
Laravel 10.0 2023年1月(January 2023)
Laravel 11.0 2024年1月(January 2024)
ohki_suguru.phpohki_suguru.php

新機能

Anonymous Migtration

そもそもMigration自体にそれぞれ名前をつける必要があるんだっけ?という疑問から生まれた機能。

該当Issueはこちらで参考の書き方は次のとおり。

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

クエリビルダインターフェースが提供されるようになる。これにより補完周りがかなり便利に。
こちら のプルリクエストにもあるように、補完が効いているときに、「Query\Builder」なのか「Eloquent\Builder」なのか「Eloquent\Relation」なのかによって補完が間違っているせいで一度エラーが出たなんて経験がある程度補完を使ったことがある人なら誰しもあるはず。そのエラーが出なくなるらしい。

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

PHP 8 String Functions

\Illuminate\Support\Strクラスの内部でのstr_contains() 、 str_starts_with() 、およびstr_ends_with()のphpの標準関数の利用が始まる。今までphpの標準関数に文字列の中に特定nの文字が含まれるのかなどといった関数がなかったため、Laravelでは、独自のラッパーメソッドを実装していた。今回でその独自実装でなくなり、標準関数の利用が始まる

プルリクエストは こちら

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

From SwiftMailer to Symfony Mailer

プルリクエストはこちら

SymfonyがSwiftMailerを非推奨としたため、Laravel9で、すべてのメールトランスポートにSymfonyMailerを使用するように変更された

Symfony deprecated SwiftMailer and Laravel 9 makes the change to use Symfony Mailer for all the mail transports. This does open up a few breaking changes and you can review the PR for all the details. The Laravel 9 upgrade guide will include instructions once it's officially released.

参考

https://laravel-news.com/laravel-anonymous-migrations
https://www.pnkts.net/2021/07/09/laravel-9-release-date
https://laravel-news.com/laravel-9

ohki_suguru.phpohki_suguru.php

LTSにおけるアップデート(6.x -> 9.x)について

Laravel8での変更が鬼門となりそう

  1. モデルファクトリが8からクラスベースの書き方に変更があった。しばらくは一旦ヘルパーで捌けるとはいえ、長期的なことを考えると、書き換えておいた方が良さそう

予定されている8.x->9.xのアップグレードガイド

https://laravel.com/docs/master/upgrade#upgrade-9.0

2021-11^16現在におけるスクショ

このスクラップは2021/11/29にクローズされました