How to update column value in laravel

后端 未结 3 1150
小鲜肉
小鲜肉 2020-12-23 19:49

I have a page model. It has following columns in database table:

  • id
  • title
  • image
  • body

I want to update only \"image\"

3条回答
  •  失恋的感觉
    2020-12-23 20:34

    Version 1:

    // Update data of question values with $data from formulay
    $Q1 = Question::find($id);
    $Q1->fill($data);
    $Q1->push();
    

    Version 2:

    $Q1 = Question::find($id);
    $Q1->field = 'YOUR TEXT OR VALUE';
    $Q1->save();
    

    In case of answered question you can use them:

    $page = Page::find($id);
    $page2update = $page->where('image', $path);
    $page2update->image = 'IMGVALUE';
    $page2update->save();
    

提交回复
热议问题