编程

Laravel 11.24 发布

233 2024-09-26 02:01:00

Laravel 发布了 v11.24,新版本包括进程 Fake 的新便捷方式,外键定义的 nullOnUpdate() 方法,任务重试时支持重试多个批处理 ID 等。

app/Console/commands 路径中控制台命令的自动发现在 v11.24.0 中已被破坏。这个问题在 v11.24.1 中很快得到了修补。

建议等待补丁更新,如果你的更新和应用控制台命令丢失,这可能会让你感到困惑。

添加 prependLocation() 到 View 工厂

Noboru Shiroiwa 添加了 prependLocation() 方法到 View 工厂,你可用在 View Facade 中使用该方法:

// 之前
View::getFinder()->addLocation($path);     // ✅
View::getFinder()->prependLocation($path); // ✅
View::addLocation($path);                  // ✅
View::prependLocation($path);              // ❌
 
// 之后
View::prependLocation($path);              // ✅

添加 nullOnUpdate()方法到外键定义(ForeignKeyDefinition)

Gisu Nasrollahi 贡献了 nullOnUpdate() 方法到 ForeignKeyDefinition schema 类,这表示对引用模型的更新应将外键值设置为 null

$table->foreign('user_id')
      ->references('id')
      ->on('users')
      ->nullOnUpdate();

允许 Route::can() 中使用回退枚举(BackedEnum)

@OmegadelaRoute::can() 方法中贡献了回退枚举的支持:

// 之前
Route::post('/request', function () {...})->can(Permissions::CAN_REQUEST->value);
 
// 之后
Route::post('/request', function () {...})->can(Permissions::CAN_REQUEST);

Process Fake 结果快捷方式

Jason McCreary 为进程(Process) Fake 结果添加了两个结果快捷方式。下面第一个例子是设置退出码的便捷方式。第二个例子为抛出异常的便捷方式。

Process::fake([
    'php -l script.php' => 255,
    'cat README.txt' => new \RuntimeException('fake exception message'),
]);

以下是来自相关 PR 测试中的 Fake 操作:

// Exit code example
$factory = new Factory;
$factory->fake(['ls -la' => 1]);
 
$result = $factory->run('ls -la');
$this->assertSame(1, $result->exitCode());
$this->assertFalse($result->successful());
 
// Exception example
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('fake exception message');
 
$factory = new Factory;
 
$factory->fake(['cat me' => new \RuntimeException('fake exception message')]);
 
$factory->run('cat me');

重试识别任务时支持重试多个批处理 ID

Sean Kegel 更新了 queue:retry-batch 命令以接受多个 ID,这样多个任务可以一次性重试:

php artisan queue:retry-batch \
  '9d0ed667-8c3a-4385-8a07-aff118a21e5c' \
  '9d0ed6f1-b8dd-486b-8761-f89de0fb68e3'

Release notes

You can see the complete list of new features and updates below and the diff between 11.23.0 and 11.24.0 on GitHub. The following release notes are directly from the changelog:

v11.24.0