tobyzerner / json-api-server

A JSON:API server implementation in PHP.
https://tobyzerner.github.io/json-api-server/
MIT License
63 stars 21 forks source link

feat: conditional linkage #110

Open SychO9 opened 4 months ago

SychO9 commented 4 months ago

We have a use case where we need to enable linkage for a ToMany relation, but only when the Show endpoint is related to the resource itself and not another (another can be when inclusion is in effect instead).

So we do something along the lines of

ToMany::make('posts')
    ->withLinkage(function (Context $context) {
          return $context->showing(self::class);
     })