public function post($parentUuid, Request $request)
    {
        // Check parent exists
        $parentModel = static::$parentModel;
        $parentResource = $parentModel::findOrFail($parentUuid);

        // Authorize ability to create children model for parent
        $this->authorizeUserAction($this->parentAbilitiesRequired['create'], $parentResource);

        // Authorize ability to create this model
        $this->authorizeUserAction('create');

        $requestData = $request->input();
        $model = new static::$model;

        // Validate
        $this->restfulService->validateResource($model, $requestData);

        // Set parent key in request data
        $resource = new $model($requestData);

        $parentRelation = $parentResource->{$this->getChildRelationNameForParent($parentResource, static::$model)}();
        $resource->{$parentRelation->getForeignKeyName()} = $parentUuid;

        // Create model in DB
        $resource = $this->restfulService->persistResource($resource);

        // Retrieve full model
        $resource = $model::with($model::$localWith)->where($model->getKeyName(), '=', $resource->getKey())->first();

        if ($this->shouldTransform()) {
            $response = $this->response->item($resource, $this->getTransformer())->setStatusCode(201);
        } else {
            $response = $resource;
        }

        return $response;
    }
public function post($parentUuid, Request $request)
    {
        // Check parent exists
        $parentModel = static::$parentModel;
        $parentResource = $parentModel::findOrFail($parentUuid);

        // Authorize ability to create children model for parent
        $this->authorizeUserAction($this->parentAbilitiesRequired['create'], $parentResource);

        // Authorize ability to create this model
        $this->authorizeUserAction('create');

        $requestData = $request->input();
        $model = new static::$model;

        // Validate
        $this->restfulService->validateResource($model, $requestData);

        // Set parent key in request data
        $resource = new $model($requestData);

        $parentRelation = $parentResource->{$this->getChildRelationNameForParent($parentResource, static::$model)}();
        $resource->{$parentRelation->getForeignKeyName()} = $parentUuid;

        // Create model in DB
        $resource = $this->restfulService->persistResource($resource);

        // Retrieve full model
        $resource = $model::with($model::$localWith)->where($model->getKeyName(), '=', $resource->getKey())->first();

        if ($this->shouldTransform()) {
            $response = $this->response->item($resource, $this->getTransformer())->setStatusCode(201);
        } else {
            $response = $resource;
        }

        return $response;
    }
public function post ( $ parentUuid , Request $ request ) { // Check parent exists $ parentModel = static :: $ parentModel ; $ parentResource = $ parentModel :: findOrFail ( $ parentUuid ) ; // Authorize ability to create children model for parent $ this -> authorizeUserAction ( $ this -> parentAbilitiesRequired [ 'create' ] , $ parentResource ) ; // Authorize ability to create this model $ this -> authorizeUserAction ( 'create' ) ; $ requestData = $ request -> input ( ) ; $ model = new static :: $ model ; // Validate $ this -> restfulService -> validateResource ( $ model , $ requestData ) ; // Set parent key in request data $ resource = new $ model ( $ requestData ) ; $ parentRelation = $ parentResource -> { $ this -> getChildRelationNameForParent ( $ parentResource , static :: $ model ) } ( ) ; $ resource -> { $ parentRelation -> getForeignKeyName ( ) } = $ parentUuid ; // Create model in DB $ resource = $ this -> restfulService -> persistResource ( $ resource ) ; // Retrieve full model $ resource = $ model :: with ( $ model :: $ localWith ) -> where ( $ model -> getKeyName ( ) , '=' , $ resource -> getKey ( ) ) -> first ( ) ; if ( $ this -> shouldTransform ( ) ) { $ response = $ this -> response -> item ( $ resource , $ this -> getTransformer ( ) ) -> setStatusCode ( 201 ) ; } else { $ response = $ resource ; } return $ response ; }
Request to create the child resource owned by the parent resource

@oaram string $parentUuid Parent's UUID
@param Request $request
@return \Dingo\Api\Http\Response
@throws HttpException
Request to create the child resource owned by the parent resource