编程

Laravel 8.78发布

947 2022-01-08 18:00:30

Laravel 团队发布了8.78版本,更新包括:为默认密码验证规则添加了自定义规则,mergerIfMissing() 请求方法,测试的批量计数的断言,等等

定义额外的默认密码验证规则

Ash Allen 贡献了使用 rules() 方法自定义默认密码验证规则的实现方式。

Password::defaults(function () {
    return Password::min(8)
        ->symbols()
        ->mixedCase()
        ->uncompromised()
        ->rules(new ZxcvbnRule());
});

rules() 方法接收一个 rule, 或者rules数组,或者验证规则的闭包。

Merge Request Data if Missing 如果缺失则合并请求数据

David Peach 贡献了mergeIfMissing() 方法,当请求数据中的某个键缺失时,可以将新的数据合并到请求数据中。

比如,如果表单中的复选框没有被选中,数据发到服务器。以前你可能会这样处理:

if ($request->missing('boolean_setting')) {
    $request->merge(['boolean_setting' => 0]);
}

现在你可以这样合并缺失的值定义:

$request->mergeIfMissing(['boolean_setting' => 0])

断言 Batch 数量 

@Chrysanthos 为Bus门面贡献了assertBatchCount() 方法,用以断言有多少batch被分发。

Bus::assertBatchCount(3);

HTML 字符串方法

Lars Klopstra 为Str 和Stringable 类贡献了toHtmlString()方法:

// Before
new HtmlString(Str::of($content)->markdown());
 
// After
Str::of($content)
    ->markdown()
    ->html();

v8.78.0

Added

  • Added schedule:clear-mutex command (#40135)
  • Added ability to define extra default password rules (#40137)
  • Added a mergeIfMissing method to the Illuminate Http Request class (#40116)
  • Added Illuminate/Support/MultipleInstanceManager (40913ac)
  • Added SimpleMessage::lines() (#40147)
  • Added Illuminate/Support/Testing/Fakes/BusFake::assertBatchCount() (#40217)
  • Enable only-to-others functionality when using Ably broadcast driver (#40234)
  • Added ability to customize json options on JsonResource response (#40208)
  • Added Illuminate/Support/Stringable::toHtmlString() (#40247)

Changed

  • Improve support for custom Doctrine column types (#40119)
  • Remove an useless check in Console Application class (#40145)
  • Sort collections by key when first element of sort operation is string (even if callable) (#40212)
  • Use first host if multiple in Illuminate/Database/Console/DbCommand::getConnection() (#40226)
  • Improvement in the Reflector class (#40241)

Fixed

  • Clear recorded calls when calling Http::fake() (#40194)
  • Fixed attribute casting (#40245, c0d9735)