Laravel 8.79 发布:分页 onLastPage 、全文搜索 whereFulltext 、Stringable 方法
Laravel团队发布了8.79,其中包括MySQL和PostgreSQL的全文搜索、新的Stringable方法以及v8.x中的最新更改。
Paginator onLastPage() 方法
Johan van Helden
向Paginator提供了一个onLastPage()
方法,该方法有助于澄清最后一页的逻辑:
@if ($paginator->onFirstPage())
{{-- ... --}}
@endif
{{-- Before --}}
@if (!$paginator->hasMorePages())
{{-- ... --}}
@endif
{{-- After --}}
@if ($paginator->onLastPage())
{{-- ... --}}
@endif
允许方法类型的变量依赖
Léo Colombaro有助于在调用可调用函数时使用variadic进行依赖项注入。下面是pull请求的一个示例:
$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']);
});
// 在标题和正文全文索引中搜索 "databases"...
$articles = DB::table('articles')
->whereFulltext(['title', 'body'], 'database')
->get();
// 使用布尔模式在标题和正文全文索引中搜索"databases"...
$articles = DB::table('articles')
->whereFulltext(['title', 'body'], 'database', ['mode' => 'boolean'])
->get();
// 使用扩展查询在标题和正文全文索引中搜索"databases"...
$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()
方法的工作方式也一样。但是,字符串必须包含所有预期的匹配项,才能使触发闭包调用的条件 true
。
Travis Elkins 也贡献了其他 Stringable
的方法 Pull Request #40320:
- endsWith()
- exactly()
- is()
- isAscii()
- isUuid()
- test()
- startsWith()
发行说明
您可以在下面看到新功能和更新的完整列表以及它们之间的差异 8.78.0 and 8.79.0 在GitHub上。以下发行说明直接来自 v8.79.0 release notes:
v8.79.0
新增
- 向分页器添加了onLastPage方法 ( #40265 )
- 允许方法类型的变量依赖项 ( #40255 )
- 添加扩展 ### ably/ably-php
to composer.json to suggest ( #40277 ) - 实现MySQL和PostgreSQL的全文搜索 ( #40129 )
- 将whenContains和whenContains全部添加到Stringable ( #40285 )
- 支持LogManager中的操作级配置 ( #40305 )
- 将WhenEndWith()、whenExactly()、whenStartsWith()等添加到Stringable ( #40320 )
- 可以轻松地向PendingBatch添加其他选项 ( #40333 )
- 向MigrationStarted/MigrationEnded事件添加了方法 ( #40334 )
修复了
- 修复了邮件Mailgun和SES一起使用时的问题( #40254 )
- 修复了带分数的数字 ( #40278 )
- 修复了使用HasManyThrough进行光标分页 ( #40300 )
- 修复了虚拟属性 ( 29a6692 )
- 修复了时区选项 ### schedule:list
command ( #40304 ) - Fixed Doctrine type mappings creating too many connections ( #40303 )
- 修复了 容器外解析蓝图类的问题 ( #40307 )
- 枚举验证规则句柄类型不匹配 ( #40362 )
已更改
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。