Skip to content

Commit 65a406a

Browse files
committed
Update docs for ResourceDTO
1 parent b611dea commit 65a406a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,21 @@ class UserController extends Controller
10411041
}
10421042
```
10431043

1044+
You can also return a collection/list of your DTOs as a response using the `ResourceDTO::collection()` method:
1045+
1046+
```php
1047+
class UserController extends Controller
1048+
{
1049+
public function index()
1050+
{
1051+
return UserResourceDTO::collection(User::all());
1052+
}
1053+
}
1054+
```
1055+
1056+
This way every item in the collection will be converted to a `UserResourceDTO` instance before sending
1057+
the response to the client, using all the typing, casting and mapping features of your DTO class.
1058+
10441059
To generate a `ResourceDTO` you can use the `--resource` flag:
10451060

10461061
```bash

0 commit comments

Comments
 (0)