2016-11-17 124 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">