src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php
protected function createResourceCallable()
    {
        return function (array $data, array $values, ErrorBag $errorBag) {
            $model = $this->getDataModel()->newInstance();

            foreach ($values as $attribute => $value) {
                $model->setAttribute($attribute, $value);
            }

            if (!empty($data['id'])) {
                $model->setAttribute($model->getKeyName(), $data['id']);
            }

            try {
                $model->save();

                //We need to load the model from the DB in case the user is utilizing getRequiredFields() on the transformer.
                $model = $model->fresh();
            } catch (\Exception $e) {
                $errorBag[] = new Error('creation_error', 'Resource could not be created');
                throw $e;
            }

            return $model;
        };
    }
protected function createResourceCallable()
    {
        return function (array $data, array $values, ErrorBag $errorBag) {
            $model = $this->getDataModel()->newInstance();

            foreach ($values as $attribute => $value) {
                $model->setAttribute($attribute, $value);
            }

            if (!empty($data['id'])) {
                $model->setAttribute($model->getKeyName(), $data['id']);
            }

            try {
                $model->save();

                //We need to load the model from the DB in case the user is utilizing getRequiredFields() on the transformer.
                $model = $model->fresh();
            } catch (\Exception $e) {
                $errorBag[] = new Error('creation_error', 'Resource could not be created');
                throw $e;
            }

            return $model;
        };
    }
protected function createResourceCallable ( ) { return function ( array $ data , array $ values , ErrorBag $ errorBag ) { $ model = $ this -> getDataModel ( ) -> newInstance ( ) ; foreach ( $ values as $ attribute => $ value ) { $ model -> setAttribute ( $ attribute , $ value ) ; } if ( ! empty ( $ data [ 'id' ] ) ) { $ model -> setAttribute ( $ model -> getKeyName ( ) , $ data [ 'id' ] ) ; } try { $ model -> save ( ) ; //We need to load the model from the DB in case the user is utilizing getRequiredFields() on the transformer. $ model = $ model -> fresh ( ) ; } catch ( \ Exception $ e ) { $ errorBag [ ] = new Error ( 'creation_error' , 'Resource could not be created' ) ; throw $ e ; } return $ model ; } ; }
Reads the input and creates and saves a new Eloquent Model.

@return callable
@codeCoverageIgnore
Reads the input and creates and saves a new Eloquent Model .