编程

Laravel 8.79发布

984 2022-01-14 05:23:33

Laravel 发布了8.79版本, 更新了MySQL和PostgreSQL的全文搜索,新的Stringable方法等

Paginator分页器onLastPage()方法

Johan van Helden 贡献了分页器的onLastPage()方法,用以声明最后一页的业务逻辑:

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

Allow Method Typed Variadic Dependencies

Léo Colombaro 贡献了调用callable时可变依赖注入的能力。例子:

$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的自然语言全文搜索。举例:

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 贡献了两个Stringabl方法,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 同时也贡献了一些其他的Stringable 方法:

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

v8.79.0

Added

  • Added onLastPage method to the Paginator ( #40265 )
  • Allow method typed variadics dependencies ( #40255 )
  • Added ### ably/ably-php
    to composer.json to suggest ( #40277 )
  • Implement Full-Text Search for MySQL & PostgreSQL ( #40129 )
  • Added whenContains and whenContainsAll to Stringable ( #40285 )
  • Support action_level configuration in LogManager ( #40305 )
  • Added whenEndsWith(), whenExactly(), whenStartsWith(), etc to Stringable ( #40320 )
  • Makes it easy to add additional options to PendingBatch ( #40333 )
  • Added method to MigrationsStarted/MigrationEnded events ( #40334 )

Fixed

  • Fixed failover mailer when used with Mailgun & SES mailers ( #40254 )
  • Fixed digits_between with fractions ( #40278 )
  • Fixed cursor pagination with HasManyThrough ( #40300 )
  • Fixed virtual attributes ( 29a6692 )
  • Fixed timezone option in ### schedule:list
    command ( #40304 )
  • Fixed Doctrine type mappings creating too many connections ( #40303 )
  • Fixed of resolving Blueprint class out of the container ( #40307 )
  • Handle type mismatch in the enum validation rule ( #40362 )

Changed

  • Automatically add event description when scheduling a command ( #40286 )
  • Update the Pluralizer Inflector instanciator ( #40336 )