Skip to content

Commit 2e11b04

Browse files
committed
update MakeApiTransformerCommand so that a custom generated Transformer can leverage a DTO instead of a Eloquent Builder Collection. In generation this will be asked and checked if a spatie/laravel-data DTO you specify exists
1 parent 19943b8 commit 2e11b04

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stubs/ApiTransformer.stub

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<?php
22
namespace {{ namespace }};
33

4+
{{ dtoNamespace }}
5+
6+
use Rupadana\ApiService\Attributes\UsesDTO;
47
use Illuminate\Http\Resources\Json\JsonResource;
58

9+
{{ dtoUsesDtoAttribute }}
610
class {{ apiTransformerClass }} extends JsonResource
711
{
812

913
/**
10-
* Transform the resource into an array.
14+
* Transform the resource via a DTO into an array.
1115
*
1216
* @param \Illuminate\Http\Request $request
1317
* @return array
1418
*/
1519
public function toArray($request)
1620
{
17-
return $this->resource->toArray();
21+
{{ returnToArray }}
1822
}
1923
}

0 commit comments

Comments
 (0)