编程

Laravel 8.76 发布了

1453 2021-12-20 15:07:26

Laravel 团队发布了 8.76 版本,包括 afterRefreshingDatabase()测试方法,MySQL invisible 修饰符支持,新的字符串方法以及v8.x 的最新更新

After Refreshing Database 测试方法

Luke Downing 贡献了 afterRefreshingDatabase 方法。当你运行 miration 后需要在测试中直接创建种子数据时, 你可以使用该方法(详情请查看 PR 描述)

示例:

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
    use LazilyRefreshDatabase;
 
    protected function afterRefreshingDatabase()
    {
        $this->artisan('db:seed', [
            '--class' => RoleAndPermissionSeeder::class
        ]);
    }
}

自定义子模型路由绑定

@marvin-wtt 贡献了通过 resolevRouteBindingQuery 方法重写子模型路由绑定方案。更多详情查看 RP#39929

通用 4xx 错误状态码 布尔值检查

Adam Rodriguez 为 Response 类贡献了 forbidden()unauthorized 方法。这些方法很好地理清了以下这些状态的逻辑:

// Before
if ($response->status() === 401) {
    // ...
}
 
if ($response->status() === 403) {
    // ...
}
 
// After
if ($response->unauthorized()) {
    // ...
}
 
if ($response->forbidden()) {
    // ...
}

MySQL 列的 Invisible 修饰符

Oliver Matla 贡献了 MySQL v8.0.23 引进的 invisible 修饰符支持。当某些列被标记为 invisible 时, 这些列不会被隐式(i.e, SELECT *)添加到 Laravel 模型中。这些列仍然可以显式 SELECT,除非显式需要数据,否则省略这些列很有用:

Schema::table('users', function (Blueprint $table) {
    $table->string('secret')->nullable()->invisible();
});

该特性目前仅支持 MySQL

substr_replace() 的字符串支持

Ralph J. Smit 为 StrStringable 类贡献了 substrReplace() 方法: 

// Insert a string at a certain position
$string = '1300';
 
$result = Str::substrReplace($string, ':', 2, 0);
// '13:00'
 
// Replace the remainder of a string
$result = (string) Str::of('Laravel Framework')
    ->substrReplace('– The PHP Framework for Web Artisans', 8);
// 'Laravel – The PHP Framework for Web Artisans'

v8.76.0

Added

  • Added possibility to customize child model route binding resolution (#39929)
  • Added Illuminate/Http/Client/Response::reason() (#39972)
  • Added an afterRefreshingDatabase test method (#39978)
  • Added unauthorized() and forbidden() to Illuminate/Http/Client/Response (#39979)
  • Publish view-component.stub in stub:publish command (#40007)
  • Added invisible modifier for MySQL columns (#40002)
  • Added Str::substrReplace() and Str::of($string)->substrReplace() methods (#39988)

Fixed

  • Fixed parent call in view (#39909)
  • Fixed request dump and dd methods (#39931)
  • Fixed php 8.1 deprecation in ValidatesAttributes::checkDateTimeOrder (#39937)
  • Fixed withTrashed on routes check if SoftDeletes is used in Model (#39958)
  • Fixes model:prune --pretend command for models with SoftDeletes (#39991)
  • Fixed SoftDeletes force deletion sets "exists" property to false only when deletion succeeded (#39987)
  • Fixed possible out of memory error when deleting values by reference key from cache in Redis driver (#39939)
  • Fixed Password validation failure to allow errors after min rule (#40030)

Changed

  • Fail enum validation with pure enums (#39926)
  • Remove redundant description & localize template (#39928)
  • Fixes reporting deprecations when logger is not ready yet (#39938)
  • Replace escaped dot with place holder in dependent rules parameters (#39935)
  • passthru from property to underlying query object (127334a)