-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
At the moment the resource objects support conditional attributes in the attributes and meta values. We should also add support for conditional relationships.
To do this, we need to support (in the encoder) having relations wrapped in either a conditional attribute or conditional attributes object. So the syntax on the resource would be:
public function relationships($request): iterable
{
return [
$this->relation('author'),
$this->when($request->user()->isAdmin(), $this->relation('publishedBy')),
$this->mergeWhen($request->user()->isOwner(), [
$this->relation('foo'),
$this->relation('bar'),
]),
];
}Probably we should rename the ConditionalAttr and ConditionalAttrs classes to ConditionalField and ConditionalFields considering we're now not just using them in attributes.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request