Laravel模型表单不会从数据库加载数据

时间:2018-06-01 17:14:24

标签: jquery laravel-5

使用Laravel 5.6,我正在创建一个Web。我有数据库表cat(paste(strsplit(vector,";")[[1]][c(1,4,3,6,7,5,8,2)],collapse=" ")) # If it rains, I will take an umbrella. 。我可以使用validator和jQuery向表中添加数据来保存,编辑和删除记录。

但问题是,当我点击编辑按钮时,policies字段(文本框)不会填充数据库中的值(参见图像)。

Table records

Model doesn't fetch name field value

name

PolicyController

editPolicy.blade.php

public function update(Request $request)
    {
        $validator = Validator::make($request->all() , [
        //  'branch_Id' => 'required|max:25|unique:branches,branchId',
        'name' => 'required|max:25',
        'description' => 'max:50']);

        if ($validator->passes())
        {
            $policy = Policy::find($request->policy_Id);
            $policy->name = $request->name;
            $policy->description = $request->description;
            $policy->save();
            return response()
                ->json($policy);
        }
        return response()->json(['error' => $validator->errors()
            ->all() ]);
    }

dashboard.blade.php

<div class="box-body">
               <div class="form-group">
                  <label for="exampleInputEmail1">Policy ID
                  </label>
                  <input type="text" class="form-control" id="edpid" placeholder="Enter Policy Id" disabled>
               </div>
               <div class="form-group">
                  <label for="exampleInputPassword1">Name
                  </label>
                  <input type="text" class="form-control" id="edname" placeholder="Enter Policy Name">
               </div>
               <div class="form-group">
                  <label for="exampleInputPassword1">Description
                  </label>
                  <textarea id="eddescr" class="form-control"></textarea>
               </div>
            </div>

0 个答案:

没有答案