Closed BenRutlandWeb closed 3 years ago
toArray
should always return an array. To achieve the above, use an array instead of a collected resource:
// recipe resource
public function toArray()
{
return [
'ingredients' => $this->ingredients->pluck('name'), // or whatever mapping is required
];
}
Describe the bug Nested
JsonResource
's collection should be able to return any JSONable type, not just an array.To Reproduce Steps to reproduce the behavior:
// ingredient resource public function toArray() { return $this->name; }
Expected behavior The toArray method to return any JSONable type, string, int, bool, object, array E.g.
Additional context The
toArray
method name implies the return will be an array but this seems restrictive in instances where the collection should return a simple array of strings.