Skip to content

Commit 3d3434f

Browse files
authored
Update laravel/index.md
Fix some docs about DTO
1 parent 7693a05 commit 3d3434f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

laravel/index.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ class Book
195195
{
196196
public string $id;
197197
public string $title;
198+
199+
public function __construct(string $id, string $title)
200+
{
201+
$this->id = $id;
202+
$this->title = $title;
203+
}
198204
}
199205
```
200206

@@ -224,13 +230,14 @@ namespace App\State;
224230
use ApiPlatform\Metadata\Operation;
225231
use ApiPlatform\State\ProviderInterface;
226232
use App\Models\Book as BookModel;
233+
use App\ApiResource\Book;
227234

228235
final class BookProvider implements ProviderInterface
229236
{
230237
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
231238
{
232239
$book = BookModel::find($uriVariables['id']);
233-
return new BookModel(id: $book->id, title: $book->title);
240+
return new Book(id: $book->id, title: $book->title);
234241
}
235242
}
236243
```

0 commit comments

Comments
 (0)