laravel #라라벨 #API #Resource #Collection
-
API Resource, CollectionLaravel 2020. 3. 27. 17:52
# API Resource를 내보낼 때 내용을 좀 가다듬고 싶다하면 사용 1. 서비스(Service) Resource 만들기 php artisan make:resource ServiceResource php artisan make:resource ServiceCollection @ ServiceResource(데이터 개체의 형태 정의) public function toArray($request) { return [ "id" => $this->id, "name" => $this->name, "url" => $this->url, "products" => ProductResource::collection($this->products()->get()) // 이런식도 가능 ]; } @ ServiceCollecti..