laravel-resource

Laravel Multi level relationship in API Resource

巧了我就是萌 提交于 2021-02-11 16:50:16
问题 My problem is, the api resource loading which i really not needed. Look into my Api Resource files //BoxItemResource.php public function toArray($request) { return [ 'box_id'=> $this->box_id, 'item_id'=> $this->item_id, 'item'=> new ItemResource($this->item) ]; } //ItemResource.php public function toArray($request) { return [ 'id' => $this->id, 'shipping_price' => $this->shipping_price, 'condition_id' => $this->condition_id, 'condition' => new ConditionResource($this->condition) ]; } /

Laravel Multi level relationship in API Resource

吃可爱长大的小学妹 提交于 2021-02-11 16:47:24
问题 My problem is, the api resource loading which i really not needed. Look into my Api Resource files //BoxItemResource.php public function toArray($request) { return [ 'box_id'=> $this->box_id, 'item_id'=> $this->item_id, 'item'=> new ItemResource($this->item) ]; } //ItemResource.php public function toArray($request) { return [ 'id' => $this->id, 'shipping_price' => $this->shipping_price, 'condition_id' => $this->condition_id, 'condition' => new ConditionResource($this->condition) ]; } /

Resource response is not wrapped with “data” [duplicate]

瘦欲@ 提交于 2021-01-28 11:31:10
问题 This question already has an answer here : Laravel paginate resources won't add meta (1 answer) Closed 12 months ago . I am very curious, why my resource response is not wrapped in data : This is my resource: App\Http\Resources\CategoryResource Object ( [resource] => stdClass Object ( [id] => 12 [title] => Category [description] => <p>Test</p> [with] => Array ( ) [additional] => Array ( ) ) Once this resource is returned like this: $response = $this->client->getApiResponse('/api/category/'.