[!NOTE]
我们力求记录所有可能发生的破坏性变更。 鉴于其中一些破坏性变更位于框架的隐秘部分,因此可能实际影响你的应用程序的变更只占其中一小部分。 想节省时间吗? 你可以使用 Laravel Shift 来帮助自动化你的应用程序升级。
影响可能性: 高
你应该在你的应用的 composer.json 文件中更新以下依赖:
影响的可能性: 低
对 Carbon 2.x 的支持已移除。所有 Laravel 12 应用程序现在需要 Carbon 3.x。
如果您正在使用 Laravel 安装程序 CLI 工具创建新的 Laravel 应用程序,您应该更新您的安装程序安装,使其与 Laravel 12.x 和 新的 Laravel 启动套件 兼容。如果您通过 composer global require 安装了 Laravel 安装程序,您可以使用 composer global update 更新安装程序:
composer global update laravel/installer如果你最初通过 php.new 安装了 PHP 和 Laravel,你可以只需针对你的操作系统重新运行 php.new 的安装命令,以安装最新版本的 PHP 和 Laravel 安装器:
/bin/bash -c "$(curl -fsSL https://php.new/install/mac/8.4)"# Run as administrator...
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://php.new/install/windows/8.4'))/bin/bash -c "$(curl -fsSL https://php.new/install/linux/8.4)"或者,如果您正在使用 Laravel Herd 捆绑的 Laravel 安装器副本,您应该将您的 Herd 安装更新到最新版本。
DatabaseTokenRepository 构造函数签名影响的可能性:非常低
Illuminate\Auth\Passwords\DatabaseTokenRepository 类的构造函数现在期望 $expires 参数以秒为单位给出,而不是分钟。
影响的可能性:低
当调用 Concurrency::run 方法并传入一个关联数组时,并发操作的结果现在将返回并附带其关联的键值:
$result = Concurrency::run([
'task-1' => fn () => 1 + 1,
'task-2' => fn () => 2 + 2,
]);
// ['task-1' => 2, 'task-2' => 4]影响可能性:低
依赖注入容器在解析类实例时,现在会遵循类属性的默认值。如果您之前依赖容器在不考虑默认值的情况下解析类实例,您可能需要调整您的应用程序以适应这种新行为:
class Example
{
public function __construct(public ?Carbon $date = null) {}
}
$example = resolve(Example::class);
// <= 11.x
$example->date instanceof Carbon;
// >= 12.x
$example->date === null;影响可能性:低
Schema::getTables()、Schema::getViews() 和 Schema::getTypes() 方法现在默认包含来自所有模式的结果。您可以传递 schema 参数以仅检索给定模式的结果:
// All tables on all schemas...
$tables = Schema::getTables();
// All tables on the 'main' schema...
$tables = Schema::getTables(schema: 'main');
// All tables on the 'main' and 'blog' schemas...
$tables = Schema::getTables(schema: ['main', 'blog']);Schema::getTableListing() 方法现在默认返回带模式限定的表名。您可以传递 schemaQualified 参数来按需更改此行为:
$tables = Schema::getTableListing();
// ['main.migrations', 'main.users', 'blog.posts']
$tables = Schema::getTableListing(schema: 'main');
// ['main.migrations', 'main.users']
$tables = Schema::getTableListing(schema: 'main', schemaQualified: false);
// ['migrations', 'users']db:table 和 db:show 命令现在输出 MySQL, MariaDB, 和 SQLite 上所有模式的结果, 就像 PostgreSQL 和 SQL Server 一样.
Blueprint 构造函数签名影响的可能性:非常低
的构造函数 Illuminate\Database\Schema\Blueprint 类现在期望一个实例 Illuminate\Database\Connection 作为其第一个参数。
影响可能性: 中等
此 HasUuids trait 现在返回与 UUID 规范第 7 版兼容的 UUID(有序 UUID)。如果你想继续使用有序的 UUIDv4 字符串作为你的模型的 ID,你应该现在使用此 HasVersion4Uuids trait:
use Illuminate\Database\Eloquent\Concerns\HasUuids; // [tl! remove]
use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids as HasUuids; // [tl! add]HasVersion7Uuids 特性已被移除。如果您之前正在使用此特性,您应该改用 HasUuids 特性,它现在提供相同的行为。
影响可能性:低
此 $request->mergeIfMissing() 方法现在允许使用“点”符号合并嵌套数组数据。如果您之前依赖此方法来创建包含键的“点”符号版本的顶级数组键,您可能需要调整您的应用程序以适应此新行为:
$request->mergeIfMissing([
'user.last_name' => 'Otwell',
]);影响可能性:低
如果您的应用未在文件系统配置中显式定义 local 磁盘,Laravel 现在会将 local 磁盘的根目录默认设置为 storage/app/private。在之前的版本中,这默认设置为 storage/app。因此,除非另行配置,否则对 Storage::disk('local') 的调用将从 storage/app/private 读取并写入。要恢复之前的行为,您可以手动定义 local 磁盘并设置所需的根路径。
影响的可能性: 低
image 验证规则默认不再允许 SVG 图片。如果您在使用 image 规则时希望允许 SVG,则必须明确允许它们:
use Illuminate\Validation\Rules\File;
'photo' => 'required|image:allow_svg'
// Or...
'photo' => ['required', File::image(allowSvg: true)],我们还鼓励您查看 laravel/laravel GitHub 仓库中的更改。虽然这些更改很多不是必需的,但您可能希望使这些文件与您的应用程序保持同步。这些更改中的一部分将在此升级指南中介绍,但其他部分,例如对配置文件或注释的更改,则不会。您可以轻松地使用 GitHub 比较工具查看更改,并选择对您重要的更新。