1. Accueil
  2. Articles
2 min de lecture
146 vues

Laravel 8.79 est disponible

Image d'illustration pour Laravel 8.79 est disponible

L'équipe Laravel a publié la version 8.79 avec une recherche en full-text pour MySQL et PostgreSQL, de nouvelles méthodes pour la classe Stringable et les dernières modifications de la branche v8.x.

Méthode de pagination onLastPage()

Johan van Helden a contribué une méthode onLastPage() au Paginator qui permet de clarifier la logique autour de la dernière page :

1@if ($paginator->onFirstPage())
2 {{-- ... --}}
3@endif
4 
5{{-- Before --}}
6@if (!$paginator->hasMorePages())
7 {{-- ... --}}
8@endif
9 
10{{-- After --}}
11@if ($paginator->onLastPage())
12 {{-- ... --}}
13@endif
1@if ($paginator->onFirstPage())
2 {{-- ... --}}
3@endif
4 
5{{-- Before --}}
6@if (!$paginator->hasMorePages())
7 {{-- ... --}}
8@endif
9 
10{{-- After --}}
11@if ($paginator->onLastPage())
12 {{-- ... --}}
13@endif

Autoriser les dépendances typées

Léo Colombaro a contribué la possibilité d'utiliser variadic pour l'injection de dépendances lors de l'appel d'un callable. Voici un exemple tiré de la pull request :

1$app->bind(Filter::class, function ($app) {
2 return [
3 $app->make(NullFilter::class),
4 $app->make(ProfanityFilter::class),
5 $app->make(TooLongFilter::class),
6 ];
7});
8 
9$app->call(function (Logger $logger, Filter ...$filters) {
10 // ...
11});
1$app->bind(Filter::class, function ($app) {
2 return [
3 $app->make(NullFilter::class),
4 $app->make(ProfanityFilter::class),
5 $app->make(TooLongFilter::class),
6 ];
7});
8 
9$app->call(function (Logger $logger, Filter ...$filters) {
10 // ...
11});

Implementation de la recherche full-text pour MySQL et PostgreSQL

Dries Vints contribue à la recherche full-text en langage naturel pour MySQL et PostgreSQL. Voici quelques exemples tirés de la Pull Request #40129 :

1Schema::create('articles', function (Blueprint $table) {
2 $table->id('id');
3 $table->string('title', 200);
4 $table->text('body');
5 $table->fulltext(['title', 'body']);
6});
7 
8// Search for "databases" in the title and body fulltext index...
9$articles = DB::table('articles')
10 ->whereFulltext(['title', 'body'], 'database')
11 ->get();
12 
13// Search for "databases" in the title and body fulltext index with boolean mode...
14$articles = DB::table('articles')
15 ->whereFulltext(['title', 'body'], 'database', ['mode' => 'boolean'])
16 ->get();
17 
18// Search for "databases" in the title and body fulltext index with an expanded query...
19$articles = DB::table('articles')
20 ->whereFulltext(['title', 'body'], 'database', ['expanded' => true])
21 ->get();
1Schema::create('articles', function (Blueprint $table) {
2 $table->id('id');
3 $table->string('title', 200);
4 $table->text('body');
5 $table->fulltext(['title', 'body']);
6});
7 
8// Search for "databases" in the title and body fulltext index...
9$articles = DB::table('articles')
10 ->whereFulltext(['title', 'body'], 'database')
11 ->get();
12 
13// Search for "databases" in the title and body fulltext index with boolean mode...
14$articles = DB::table('articles')
15 ->whereFulltext(['title', 'body'], 'database', ['mode' => 'boolean'])
16 ->get();
17 
18// Search for "databases" in the title and body fulltext index with an expanded query...
19$articles = DB::table('articles')
20 ->whereFulltext(['title', 'body'], 'database', ['expanded' => true])
21 ->get();

Nouvelles méthodes Stringable

Travis Elkins a contribué deux méthodes Stringable, whenContains() et whenContainsAll() :

1// Before
2$stringable = Str::of('some important announcement');
3 
4if ($stringable->contains(['important', 'emergency'])) {
5 $stringable->upper();
6}
7 
8return (string) $stringable;
9 
10// After
11return (string) Str::of('some important announcement')
12 ->whenContains(
13 ['important', 'emergency'],
14 fn (Stringable $stringable) => $stringable->upper(),
15 );
16}
1// Before
2$stringable = Str::of('some important announcement');
3 
4if ($stringable->contains(['important', 'emergency'])) {
5 $stringable->upper();
6}
7 
8return (string) $stringable;
9 
10// After
11return (string) Str::of('some important announcement')
12 ->whenContains(
13 ['important', 'emergency'],
14 fn (Stringable $stringable) => $stringable->upper(),
15 );
16}

La méthode whenContainsAll() fonctionnerait de la même manière. Cependant, la chaîne doit contenir toutes les correspondances attendues pour que la condition soit true et déclenche l'appel de fermeture.

Travis Elkins a également contribué d'autres méthodes Stringable dans la Pull Request #40320 :

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

Notes de version

Vous pouvez consulter la liste complète des nouvelles fonctionnalités et des mises à jour ci-dessous, ainsi que les différences entre les versions 8.78.0 and 8.79.0 sur GitHub. Les notes de mise à jour suivantes sont directement issues des notes de mise à jour de la version 8.79.0

Cet article a été initialement publié sur Laravel News