douyun7285 2019-04-07 14:45
浏览 36
已采纳

如何在laravel中编辑数据库的一行中的一列

How to edit one column in a row of the database in laravel

I can't update one column of row has multiple columns by laravel

My edit :

public function edit($id)
{
    $addremark=bookappoitment::findOrFail($id);
    return view('admin.ManageTime.addremarks', compact('addremark'));
}

My update:

public function update(Request $request, $id)
{
    $request->validate([
      'Remarks'=>'required'
    ]); 

    $data=bookappoitment::find($id);
    $data->Remarks = $request->get('Remarks');
    $data->save();

    return view('/home');
}

link to update:

<a href="{{route('BookAppoint.update',$addremark->id)}}">Update</a>

form:

<div class="panel-body">
  <div class="row">
    <div class="col-lg-6">
      <div class="form-group">
        <label>Remarks :</label>
        <textarea class="form-control" rows="10" name="Remarks" placeholder="Remarks">{{ $addremark->Remarks }}</textarea>
      </div>

      <a class="btn btn-success btn-mini deleteRecord " href="{{route('BookAppoint.update',$addremark->id)}}">Update</a>

    </div>
  </div>
</div>
  • 写回答

1条回答 默认 最新

  • dongshijiao6890 2019-04-07 14:53
    关注

    You can update 1 (or more, just add to the array) column through the DB class.

    DB::table('yourTable')->where('id', $id)->update(['remarks' => $request->input('Remarks')]);
    

    You can also do it for a model like so:

    bookappoitment::where('id', $id)->update(['remarks' => $request->input('Remarks')]);
    

    It's in the Laravel documentation here.


    <form class="" action="index.html" method="{{ route('BookAppoint.update', $addremark->id) }}">
      @method('PATCH')
      @csrf
    
      <div class="panel-body">
        <div class="row">
    
          <div class="col-lg-6">
            <div class="form-group">
              <label for="Remarks">Remarks :</label>
              <textarea name="remarks" rows="10" placeholder="Remarks">{{$addremarks->Remarks}}</textarea>
            </div>
          </div>
    
          <input type="submit" name="submit" value="Update">
    
        </div>
      </div>
    
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?