Error when included resources
lironesamoun opened this issue · 1 comments
lironesamoun commented
hi,
I try to do the following:
http://127.0.0.1:8000/api/v1/assets/27?include=histories
The relationship is defined between an asset and a history. An asset has multiple histories and one history belong to an asset.
I have this error:
ErrorException
assert(): assert(is_array($data) === true || $data instanceof Closure || is_object($data) === true || $data === null) failed
On my Schema.php
public function getRelationships($asset, $isPrimary, array $includeRelationships)
{
return [
'histories' => [
self::SHOW_SELF => true,
self::SHOW_RELATED => true,
self::SHOW_DATA => isset($includeRelationships['histories']),
self::DATA => function () use ($asset) {
return "$asset->name";
},
],
];
}
On the validator, the "histories" is included to the array.
Could you please help on that ? Thank
lindyhopchris commented
The answer is this line is incorrect:
return "$asset->name";
You're returning a string, which is not a valid value for relationship data.
Should be:
return $asset->histories
assuming the relationship is called histories
on your Asset
model class.