cyberfly
9/12/2017 - 8:07 AM

Store table row data in JSON

Store table row data in JSON

evaluation_analyses.forEach(function (evaluation_analysis) {

                        formData[evaluation_analysis.field_code] = evaluation_analysis.value;

                        //if equal to json column, need to parse it

                        if (evaluation_analysis.field_code==='value_proposition') {
                            
                            var value_proposition = JSON.parse(evaluation_analysis.value);
                            
                            formData.value_proposition = value_proposition;
                            
                        }
                                   
                    });
<div class="col-md-12" ng-show="vm.evaluation.internal_phase_code != 'PENDINGBA'">
            <div class="row row-risk-factors">
                <div class="col-xs-12 col-md-5">
                    <p style="padding-right: 5px">Description</p>
                </div>
                <div class="col-xs-12 col-md-5">
                    <p>Comments</p>
                </div>
            </div>
            <div class="row row-risk-factors">
                <div class="col-xs-12 col-md-5">
                    <textarea class="form-control" rows="10" ng-model="vm.formData.value_proposition.descriptions[0]"></textarea>
                </div>
                <div class="col-xs-12 col-md-7">
                    <textarea class="form-control" rows="10" ng-model="vm.formData.value_proposition.comments[0]"></textarea>
                </div>
                <div class="col-xs-12 col-md-5">
                    <textarea class="form-control" rows="10" ng-model="vm.formData.value_proposition.descriptions[1]"></textarea>
                </div>
                <div class="col-xs-12 col-md-7">
                    <textarea class="form-control" rows="10" ng-model="vm.formData.value_proposition.comments[1]"></textarea>
                </div>
            </div>
        </div>
if ($request->exists('value_proposition')) {

            $value_proposition_json = json_encode($request->value_proposition);
            $value_proposition_analysis = EvaluationAnalysis::whereEvaluationId($evaluation_id)->whereFieldCode('value_proposition')->first();

            if (!$value_proposition_analysis) {

                $value_proposition_analysis = new EvaluationAnalysis;
                $value_proposition_analysis->evaluation_id = $evaluation_id;
                $value_proposition_analysis->field_code = 'value_proposition';
                $value_proposition_analysis->value = $value_proposition_json;
                $value_proposition_analysis->save();

            }
            else {
                $value_proposition_analysis->value = $value_proposition_json;
                $value_proposition_analysis->save();
            }

        }