#Circular dependency in Resource's

3 messages · Page 1 of 1 (latest)

topaz stag
topaz stag
#

I assumes your resources are something like

//CountryResource
return [
  'country'=>$this->resource->name,
  'cities'=> CityResource::collection($this->whenLoaded('cities'))
];
// CityResource
return [
 'city'=>$this->resource->name,
  'country'=> new CountryResource($this->whenLoaded('country'))
];

The keys(cities /country) will be shown if you have loaded the relationship, others will remain the same.

shut shoal
#

Which nested relations would you miss?
What kind of example would you like to archive?

Something like this?

return [
  'city' => [
    'id' => ...., 
    'country' => [
      // data of country
      'citiesIds' => [...] // array including all ids of all related cities
     ],
  ]
];