2016-11-17 135 views
2

我需要更新一些記錄,這是形式的行動,我的刀片MethodNotAllowedHttpException而Laravel提交表單5.2

<form class="form-vertical" role="form" method="post" action="/projects/{{ $project->id }}/collaborators/{{ $collaborator->user()->first()->id }}"> 

控制器

public function update(Request $request, $projectId, $collaboratorId) 
{ 
    $this->validate($request, [ 
      'status' => 'required', 
     ]); 

     DB::table('permissions') 
      ->where('project_id', $projectId) 
      ->where('collaborator_id', $collaboratorId) 
      ->update(['status' => $request->input('status')]); 

     return redirect()->back()->with('info','Your Permission has been updated successfully'); 



} 

路線

Route::put('projects/{projects}/collaborators/{id}',['uses'=>'[email protected]',]); 

當點擊更新按鈕產生以下錯誤

MethodNotAllowedHttpException in RouteCollection.php line 218: 

怎麼解決這個

+1

在你的路線,你已經定義了'put'方法和表單使用'POST'方法,你應該在你的表單中添加隱藏的輸入。 – Tiger

回答

0

由於@Tiger在評論中提到,

在你的路線,你已經定義的方法把你的表格是使用後 方法,你應該添加隱藏的輸入在你的形式。

添加<input type="hidden" name="_method" value="PUT">開標後form標籤。如下圖所示:

<form class="form-vertical" role="form" method="post" action="/projects/{{ $project->id }}/collaborators/{{ $collaborator->user()->first()->id }}" 

<input type="hidden" name="_method" value="PUT"> 
相關問題