我的更新代码无法在Laravel8中工作

nkcskrwz  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(201)

事实上,我在我的博客中编辑了这篇文章,但是当我尝试它时,它不能更新,而是创建了一个新的记录。我还尝试了update()函数,但它无法工作。代码怎么了?任何人,请给我一些建议,即兴创作我的代码。我想知道问题出在哪里。所以,任何人都可以详细解释,然后我会非常感激这件事。
我的代码:
邮政控制器代码:

public function update(Request $request,Post $post)
    {

        $post->user_id=$request->user()->id;
        $post->title=$request->title;
        $post->Description=$request->description;
        $post->save();
        return redirect('/show');
    }

路由文件代码:

Route::get('posts/edit/{edit}',[PostController::class,'edit']);
Route::post('/update',[PostController::class,'update']);

查看页面代码:

<form method="POST" action='/update'>
      @csrf
      <table class="table table table-striped table">
    <div class="form-group">
        <label for="name" class="col-form-label text-md-right">Title</label><br/>
    <input placeholder="Enter title here" type="text" name="title" value="{{$data->title}}" required/>
  </div>
  <div class="form-group">
    <label for="name" class="col-form-label text-md-right">Description</label>
  </div>
    <div>
    <textarea name="description" required>{{$data->description}}
    </textarea></div>
  <div>  
    <input type="submit" name="update" class="btn btn-success" value="Update" required />
  </div>
</table>
</form>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题