laravel查询生成器未封装字符串

时间:2018-10-15 16:41:07

标签: php ajax laravel

<!--Letter Addressee Name -->
<td *ngIf="!responseData.loading" class="width-1 visible-lg-table-cell">
    <input type="text" name="letterAddresseeNameTextField" ng-value= getLetterAddresseeName(responseData) ng-change = "AccountsController.addAddresseesToAccount()"><br>

</td>

<!--Preferred Addressee Name -->
<td *ngIf="!responseData.loading" class="width-1 visible-lg-table-cell">
    <input type="text" name="preferredAddresseeNameTextField" ng-value = getPreferredAddresseeName(responseData) ng-change = "AccountsController.addAddresseesToAccount()" ><br>

</td>

我遇到的主要问题是所构建的SQL查询没有封装字符串值。因此,如果我将$ data直接传递给model-> save()命令,它将生成此sql

                /*
             * ajax submission
             * data[545][App\ReportNames][ReportID]: 545
               data[545][App\ReportNames][ReportName]: Cabinet Value
               data[545][App\ReportNames][ReportType]: PHP
               data[545][App\ReportNames][ObjectName]: CabinetValueReport
               data[545][App\ReportNames][ObjectType]: Code
               data[545][App\ReportNames][Comments]: ObjName refs Model
               data[545][App\ReportNames][Disabled][]: 0
             *
             */
            $data = $request->data[$Key[0]][$model][$column];
            if(!is_numeric($data)){
                $data = array_map('strval',$request->data[$Key[0]][$model][$column]);
                //"message": "array_map(): Argument #2 should be an array",
                $data = (string)$request->data[$Key[0]][$model][$column];
                //"message": "Array to string conversion",
                $data = "'".$data."'"; 
                // "message": "Array to string conversion",
                $data = $data->__toString(); 
                //"message": "Call to a member function __toString() on string",
            }
            $update->save(); //Array to string conversion ... sql clause with string values not enclosed by quotes

很显然,如果不包装字符串参数,我将无法保存此信息。因此,这在sql服务器管理器中完全可以正常运行。

update [ReportNames] set [Comments] = ObjName refs Model, [Disabled] = 0 where [ReportID] = 545

有关如何修改请求中发送的字符串值的任何建议,将不胜感激。

0 个答案:

没有答案