编程

Laravel 8.76 发布了

898 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

Common 4xx Error Status Code Boolean Checks

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

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

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

Invisible Modifier for MySQL Columns

Invisible修饰符

Oliver Matla 贡献了MySQL v8.0.23引进的invisible修饰符支持。当某些列被标记为invisible 时, 这些列 不会被

Oliver Matla contributed invisible modifier support, introduced in MySQL v8.0.23. When columns are marked as invisible, they are not implicitly (i.e., SELECT *) and thus not hydrated in Laravel models. These columns can still be explicitly selected, making it useful to omit unless you explicitly need the data:

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

该特性目前仅支持MySQL

substr_replace() 的字符串支持

Ralph J. Smit 为 Str 和 Stringable 类贡献了 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)