public function relatedPost(ApiRequest $request, $resourceModel)
    {
        $requestModel = $request->asRequestModel();

        $this->validate($requestModel, $this->getCreatingRules());

        $ids = (array)$requestModel->id();

        /** @var BelongsToMany $relation */
        $relation = $this->getRelation($resourceModel);
        $this->beforeCreating($ids, $relation);

        $requestModel->map(function (RequestModel $model) use ($relation) {
            $this->createRelationshipModel($relation, $model);
        });

        return $this->getRelation($resourceModel->fresh())->get();
    }
public function relatedPost(ApiRequest $request, $resourceModel)
    {
        $requestModel = $request->asRequestModel();

        $this->validate($requestModel, $this->getCreatingRules());

        $ids = (array)$requestModel->id();

        /** @var BelongsToMany $relation */
        $relation = $this->getRelation($resourceModel);
        $this->beforeCreating($ids, $relation);

        $requestModel->map(function (RequestModel $model) use ($relation) {
            $this->createRelationshipModel($relation, $model);
        });

        return $this->getRelation($resourceModel->fresh())->get();
    }
public function relatedPost ( ApiRequest $ request , $ resourceModel ) { $ requestModel = $ request -> asRequestModel ( ) ; $ this -> validate ( $ requestModel , $ this -> getCreatingRules ( ) ) ; $ ids = ( array ) $ requestModel -> id ( ) ; /** @var BelongsToMany $relation */ $ relation = $ this -> getRelation ( $ resourceModel ) ; $ this -> beforeCreating ( $ ids , $ relation ) ; $ requestModel -> map ( function ( RequestModel $ model ) use ( $ relation ) { $ this -> createRelationshipModel ( $ relation , $ model ) ; } ) ; return $ this -> getRelation ( $ resourceModel -> fresh ( ) ) -> get ( ) ; }
post request on To-Many relationship

@param ApiRequest $request
@param Model $resourceModel
@return Model
@throws \Exception
post request on To - Many relationship