public function create(Request $request)
    {
        $instance   = $this->resolveModel();
        $connection = $instance->getConnection();
        $affected   = [];
        $errors     = [];

        $connection->beginTransaction();
        foreach ($request->get('data') as $data) {
            $validator = $this->getValidationFactory()->make($data, $this->createRules(), $this->createMessages(), $this->attributes());
            if ($validator->fails()) {
                foreach ($this->formatErrors($validator) as $error) {
                    $errors[] = $error;
                }

                continue;
            }

            if (method_exists($this, 'creating')) {
                $data = $this->creating($instance, $data);
            }

            if (method_exists($this, 'saving')) {
                $data = $this->saving($instance, $data);
            }

            $model = $instance->newQuery()->create($data);
            $model->setAttribute('DT_RowId', $model->getKey());

            if (method_exists($this, 'created')) {
                $this->created($model, $data);
            }

            if (method_exists($this, 'saved')) {
                $this->saved($model, $data);
            }

            $affected[] = $model;
        }

        if (! $errors) {
            $connection->commit();
        } else {
            $connection->rollBack();
        }

        return $this->toJson($affected, $errors);
    }
public function create(Request $request)
    {
        $instance   = $this->resolveModel();
        $connection = $instance->getConnection();
        $affected   = [];
        $errors     = [];

        $connection->beginTransaction();
        foreach ($request->get('data') as $data) {
            $validator = $this->getValidationFactory()->make($data, $this->createRules(), $this->createMessages(), $this->attributes());
            if ($validator->fails()) {
                foreach ($this->formatErrors($validator) as $error) {
                    $errors[] = $error;
                }

                continue;
            }

            if (method_exists($this, 'creating')) {
                $data = $this->creating($instance, $data);
            }

            if (method_exists($this, 'saving')) {
                $data = $this->saving($instance, $data);
            }

            $model = $instance->newQuery()->create($data);
            $model->setAttribute('DT_RowId', $model->getKey());

            if (method_exists($this, 'created')) {
                $this->created($model, $data);
            }

            if (method_exists($this, 'saved')) {
                $this->saved($model, $data);
            }

            $affected[] = $model;
        }

        if (! $errors) {
            $connection->commit();
        } else {
            $connection->rollBack();
        }

        return $this->toJson($affected, $errors);
    }
public function create ( Request $ request ) { $ instance = $ this -> resolveModel ( ) ; $ connection = $ instance -> getConnection ( ) ; $ affected = [ ] ; $ errors = [ ] ; $ connection -> beginTransaction ( ) ; foreach ( $ request -> get ( 'data' ) as $ data ) { $ validator = $ this -> getValidationFactory ( ) -> make ( $ data , $ this -> createRules ( ) , $ this -> createMessages ( ) , $ this -> attributes ( ) ) ; if ( $ validator -> fails ( ) ) { foreach ( $ this -> formatErrors ( $ validator ) as $ error ) { $ errors [ ] = $ error ; } continue ; } if ( method_exists ( $ this , 'creating' ) ) { $ data = $ this -> creating ( $ instance , $ data ) ; } if ( method_exists ( $ this , 'saving' ) ) { $ data = $ this -> saving ( $ instance , $ data ) ; } $ model = $ instance -> newQuery ( ) -> create ( $ data ) ; $ model -> setAttribute ( 'DT_RowId' , $ model -> getKey ( ) ) ; if ( method_exists ( $ this , 'created' ) ) { $ this -> created ( $ model , $ data ) ; } if ( method_exists ( $ this , 'saved' ) ) { $ this -> saved ( $ model , $ data ) ; } $ affected [ ] = $ model ; } if ( ! $ errors ) { $ connection -> commit ( ) ; } else { $ connection -> rollBack ( ) ; } return $ this -> toJson ( $ affected , $ errors ) ; }
Process create action request.

@param Request $request
@return JsonResponse
Process create action request .