Skip to content

Commit f4a0c4f

Browse files
authored
Update laravel/index.md
Use the constructor property promotion syntax in ApiResource/Book
1 parent 3d3434f commit f4a0c4f

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

laravel/index.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,7 @@ use ApiPlatform\Metadata\Get;
193193
#[Get(uriTemplate: '/my_custom_book/{id}')]
194194
class Book
195195
{
196-
public string $id;
197-
public string $title;
198-
199-
public function __construct(string $id, string $title)
200-
{
201-
$this->id = $id;
202-
$this->title = $title;
203-
}
196+
public function __construct(public string $id, public string $title) {}
204197
}
205198
```
206199

@@ -280,8 +273,7 @@ use App\State\BookProvider;
280273
#[Get(uriTemplate: '/my_custom_book/{id}', provider: BookProvider::class)]
281274
class Book
282275
{
283-
public string $id;
284-
public string $title;
276+
public function __construct(public string $id, public string $title) {}
285277
}
286278
```
287279

0 commit comments

Comments
 (0)