Laravel 8.79版本发布

2023-06-01 laravel 版本 发布

Laravel 团队发布了 8.79,其中包含对 MySQL 和 PostgreSQL 的全文搜索、新的 Stringable 方法以及 v8.x 分支的最新更改。


分页器 onLastPage() 方法

Johan van Helden 为 Paginator 贡献了一个 onLastPage() 方法,

这有助于阐明最后一页的逻辑:

@if ($paginator->onFirstPage())
    {{-- ... --}}
@endif
 
{{-- Before --}}
@if (!$paginator->hasMorePages())
    {{-- ... --}}
@endif
 
{{-- After --}}
@if ($paginator->onLastPage())
    {{-- ... --}}
@endif

允许方法类型的可变依赖项

Léo Colombaro 贡献了在调用可调用对象时使用可变参数进行依赖注入的能力。 

这是拉取请求中的一个示例:

$app->bind(Filter::class, function ($app) {
    return [
        $app->make(NullFilter::class),
        $app->make(ProfanityFilter::class),
        $app->make(TooLongFilter::class),
    ];
});
 
$app->call(function (Logger $logger, Filter ...$filters) {
    // ...
});


为 MySQL 和 PostgreSQL 实现全文搜索

Dries Vints 为 MySQL 和 PostgreSQL 贡献了自然语言全文搜索。 

以下是来自 Pull Request #40129 的一些示例:

Schema::create('articles', function (Blueprint $table) {
    $table->id('id');
    $table->string('title', 200);
    $table->text('body');
    $table->fulltext(['title', 'body']);
});
 
// Search for "databases" in the title and body fulltext index...
$articles = DB::table('articles')
    ->whereFulltext(['title', 'body'], 'database')
    ->get();
 
// Search for "databases" in the title and body fulltext index with boolean mode...
$articles = DB::table('articles')
    ->whereFulltext(['title', 'body'], 'database', ['mode' => 'boolean'])
    ->get();
 
// Search for "databases" in the title and body fulltext index with an expanded query...
$articles = DB::table('articles')
    ->whereFulltext(['title', 'body'], 'database', ['expanded' => true])
    ->get();


新的 Stringable 方法

Travis Elkins 贡献了两个 Stringable 方法,whenContains() 和 whenContainsAll():

// Before
$stringable = Str::of('some important announcement');
 
if ($stringable->contains(['important', 'emergency'])) {
    $stringable->upper();
}
 
return (string) $stringable;
 
// After
return (string) Str::of('some important announcement')
    ->whenContains(
        ['important', 'emergency'],
        fn (Stringable $stringable) => $stringable->upper(),
    );
}


whenContainsAll() 方法的工作方式相同。 

但是,字符串必须包含所有预期的匹配项才能使触发闭包调用的条件为真。

Travis Elkins 还在 Pull Request #40320 中贡献了其他 Stringable 方法:

endsWith()
exactly()
is()
isAscii()
isUuid()
test()
startsWith()


发行说明

您可以在下面查看新功能和更新的完整列表以及 GitHub 上 8.78.0 和 8.79.0 之间的差异。 

https://github.com/laravel/framework/compare/v8.78.0...v8.79.0

以下发行说明直接来自 v8.79.0 发行说明:

https://github.com/laravel/framework/releases/tag/v8.79.0


v8.79.0

添加:

在 Paginator 中添加 onLastPage 方法 (#40265)
允许方法类型的可变参数依赖(#40255)
添加了### able/ably-php向 composer.json 提出建议 (#40277 )
为 MySQL 和 PostgreSQL 实现全文搜索 (#40129)
将 whenContains 和 whenContainsAll 添加到 Stringable (#40285)
支持 LogManager 中的 action_level 配置(#40305)
将 whenEndsWith()、whenExactly()、whenStartsWith() 等添加到 Stringable (#40320)
可以轻松地将其他选项添加到 PendingBatch (#40333)
向 MigrationsStarted/MigrationEnded 事件添加方法 (#40334)

修复:

修复了与 Mailgun 和 SES 邮件程序一起使用时的故障转移邮件程序 (#40254)
修复了带分数的 digits_between (#40278)
使用 HasManyThrough 修复光标分页(#40300)
修复了虚拟属性 (29a6692)
schedule:list 中的修复了时区选项
命令(#40304)
修复了创建过多连接的 Doctrine 类型映射 (#40303)
修复了从容器中解析蓝图类 (#40307)
处理枚举验证规则中的类型不匹配 (#40362)

改变了:

调度命令时自动添加事件描述(#40286)
更新 Pluralizer Inflector 实例化器 (#40336)

具体代码,自行代入 pull ID(比如:#40320)

https://github.com/laravel/framework/pull/40320

转:

https://laravel-news.com/laravel-8-79-0

相关文章