public function relatedItem(
        ResourceManager $resourceManager,
        ApiRequest $request,
        int $version,
        string $resource,
        $id,
        string $relationship,
        $parameter
    )
    {
        $resourceManager->version($version);

        /** @var HandlesRelationshipItemRequest $handler */
        $handler = $this->initializeHandler($resourceManager, $resource . '.' . $relationship, $request,
            HandlesRelationshipItemRequest::class);

        $parameters = $request->asParameters();

        $resourceRepository = $this->initializeRepository($resourceManager, $resource, $parameters);
        $model = $resourceRepository->findOrFail($id);

        $repository = $resourceManager->resolveRepository($resource . '.' . $relationship);

        $result = $handler->relatedItem($model, $parameter, $repository);

        $document = $this->makeDocumentFromResource($resourceManager, $resource . '.' . $relationship, $result,
            $parameters, $handler);

        if (config('json-api.response.relationships.item.links.self', false)) {
            $document->addLink('self', apiRouteRelationship($resource, $id, $relationship, null, $version));
        }
        if (config('json-api.response.relationships.item.links.related', false)) {
            $document->addLink('related', apiRoute($resource, $id));
        }

        return $this->respond($document);
    }
public function relatedItem(
        ResourceManager $resourceManager,
        ApiRequest $request,
        int $version,
        string $resource,
        $id,
        string $relationship,
        $parameter
    )
    {
        $resourceManager->version($version);

        /** @var HandlesRelationshipItemRequest $handler */
        $handler = $this->initializeHandler($resourceManager, $resource . '.' . $relationship, $request,
            HandlesRelationshipItemRequest::class);

        $parameters = $request->asParameters();

        $resourceRepository = $this->initializeRepository($resourceManager, $resource, $parameters);
        $model = $resourceRepository->findOrFail($id);

        $repository = $resourceManager->resolveRepository($resource . '.' . $relationship);

        $result = $handler->relatedItem($model, $parameter, $repository);

        $document = $this->makeDocumentFromResource($resourceManager, $resource . '.' . $relationship, $result,
            $parameters, $handler);

        if (config('json-api.response.relationships.item.links.self', false)) {
            $document->addLink('self', apiRouteRelationship($resource, $id, $relationship, null, $version));
        }
        if (config('json-api.response.relationships.item.links.related', false)) {
            $document->addLink('related', apiRoute($resource, $id));
        }

        return $this->respond($document);
    }
public function relatedItem ( ResourceManager $ resourceManager , ApiRequest $ request , int $ version , string $ resource , $ id , string $ relationship , $ parameter ) { $ resourceManager -> version ( $ version ) ; /** @var HandlesRelationshipItemRequest $handler */ $ handler = $ this -> initializeHandler ( $ resourceManager , $ resource . '.' . $ relationship , $ request , HandlesRelationshipItemRequest :: class ) ; $ parameters = $ request -> asParameters ( ) ; $ resourceRepository = $ this -> initializeRepository ( $ resourceManager , $ resource , $ parameters ) ; $ model = $ resourceRepository -> findOrFail ( $ id ) ; $ repository = $ resourceManager -> resolveRepository ( $ resource . '.' . $ relationship ) ; $ result = $ handler -> relatedItem ( $ model , $ parameter , $ repository ) ; $ document = $ this -> makeDocumentFromResource ( $ resourceManager , $ resource . '.' . $ relationship , $ result , $ parameters , $ handler ) ; if ( config ( 'json-api.response.relationships.item.links.self' , false ) ) { $ document -> addLink ( 'self' , apiRouteRelationship ( $ resource , $ id , $ relationship , null , $ version ) ) ; } if ( config ( 'json-api.response.relationships.item.links.related' , false ) ) { $ document -> addLink ( 'related' , apiRoute ( $ resource , $ id ) ) ; } return $ this -> respond ( $ document ) ; }
handles relationship item request

/public/v1/resources/{id}/relationships/{related}/{relatedId}

@param ResourceManager $resourceManager
@param ApiRequest $request
@param int $version
@param string $resource
@param string|int $id
@param string $relationship
@param string|int $parameter
@return \Illuminate\Http\JsonResponse
handles relationship item request