From dfbd829a33ec21fc15005d937510e58a378f0ec5 Mon Sep 17 00:00:00 2001 From: Julien SCHMITT Date: Sat, 12 Oct 2024 19:03:41 +0200 Subject: [PATCH 1/4] Update laravel/index.md file - Added missing 'use' statements in the laravel/index.md for clarity - Fixed a typo in a Model usage - Corrected 'ProviderInterface::class' to 'provider' in ApiServiceProvider --- laravel/index.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/laravel/index.md b/laravel/index.md index 64d6f7aedcf..f05cd04d0ca 100644 --- a/laravel/index.md +++ b/laravel/index.md @@ -230,7 +230,7 @@ final class BookProvider implements ProviderInterface public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null { $book = BookModel::find($uriVariables['id']); - return new Book(id: $book->id, title: $book->title); + return new BookModel(id: $book->id, title: $book->title); } } ``` @@ -242,6 +242,7 @@ Register the state provider: namespace App\Providers; +use App\State\BookProvider; use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\ServiceProvider; @@ -253,7 +254,7 @@ class ApiServiceProvider extends ServiceProvider return new BookProvider(); }); - $this->app->tag([BookProvider::class], ProviderInterface::class); + $this->app->tag([BookProvider::class], 'provider'); } } ``` @@ -624,6 +625,7 @@ API Platform provides an easy shortcut to some [useful filters](./filters.md), f namespace App\Models; use ApiPlatform\Metadata\ApiResource; ++use ApiPlatform\Metadata\QueryParameter; +use ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter; use Illuminate\Database\Eloquent\Model; @@ -643,6 +645,7 @@ It's also possible to enable filters on every exposed property: namespace App\Models; use ApiPlatform\Metadata\ApiResource; ++use ApiPlatform\Metadata\QueryParameter; +use ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter; +use ApiPlatform\Laravel\Eloquent\Filter\OrderFilter; use Illuminate\Database\Eloquent\Model; From 7693a05064bc5456691bd1a157a8ecf9250b6208 Mon Sep 17 00:00:00 2001 From: Julien SCHMITT Date: Mon, 14 Oct 2024 11:58:51 +0200 Subject: [PATCH 2/4] Update index.md Change 'provider' to ProviderInterface::class in laravel/index.md --- laravel/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/laravel/index.md b/laravel/index.md index f05cd04d0ca..be5bca7494a 100644 --- a/laravel/index.md +++ b/laravel/index.md @@ -243,6 +243,7 @@ Register the state provider: namespace App\Providers; use App\State\BookProvider; ++use ApiPlatform\State\ProviderInterface; use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\ServiceProvider; @@ -254,7 +255,7 @@ class ApiServiceProvider extends ServiceProvider return new BookProvider(); }); - $this->app->tag([BookProvider::class], 'provider'); + $this->app->tag([BookProvider::class], ProviderInterface::class); } } ``` From 3d3434ff19c0fcdaeaca01f697537716d78232a4 Mon Sep 17 00:00:00 2001 From: Julien SCHMITT Date: Mon, 14 Oct 2024 15:25:03 +0200 Subject: [PATCH 3/4] Update laravel/index.md Fix some docs about DTO --- laravel/index.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/laravel/index.md b/laravel/index.md index be5bca7494a..5f0fc8482e3 100644 --- a/laravel/index.md +++ b/laravel/index.md @@ -195,6 +195,12 @@ class Book { public string $id; public string $title; + + public function __construct(string $id, string $title) + { + $this->id = $id; + $this->title = $title; + } } ``` @@ -224,13 +230,14 @@ namespace App\State; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; use App\Models\Book as BookModel; +use App\ApiResource\Book; final class BookProvider implements ProviderInterface { public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null { $book = BookModel::find($uriVariables['id']); - return new BookModel(id: $book->id, title: $book->title); + return new Book(id: $book->id, title: $book->title); } } ``` From f4a0c4f95e973e0befe708d4d49c1358d23f0035 Mon Sep 17 00:00:00 2001 From: Julien SCHMITT Date: Mon, 14 Oct 2024 20:30:45 +0200 Subject: [PATCH 4/4] Update laravel/index.md Use the constructor property promotion syntax in ApiResource/Book --- laravel/index.md | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/laravel/index.md b/laravel/index.md index 5f0fc8482e3..e5dda8c9a6d 100644 --- a/laravel/index.md +++ b/laravel/index.md @@ -193,14 +193,7 @@ use ApiPlatform\Metadata\Get; #[Get(uriTemplate: '/my_custom_book/{id}')] class Book { - public string $id; - public string $title; - - public function __construct(string $id, string $title) - { - $this->id = $id; - $this->title = $title; - } + public function __construct(public string $id, public string $title) {} } ``` @@ -280,8 +273,7 @@ use App\State\BookProvider; #[Get(uriTemplate: '/my_custom_book/{id}', provider: BookProvider::class)] class Book { - public string $id; - public string $title; + public function __construct(public string $id, public string $title) {} } ```