我在RouteCollection.php中得到了MethodNotAllowedHttpException

时间:2017-06-20 06:38:36

标签: php laravel

我在MethodNotAllowedHttpException

中收到错误消息RouteCollection.php

这里是service.blade.php

<form ACTION="{{ url('backend/client/updateservice' ) }}" METHOD="POST" id="form1" name="form1" >
   <input type="hidden" name="_token" value="{{ csrf_token() }}">     
</form>

这里是route.php

Route::get('backend/client/editservice','Backend\ClientController@editservice');
Route::post('backend/client/updateservice','Backend\ClientController@updateservice');

这是ClientController.php

public function editservice()
{
  $client = Client::where('ClientID','1') -> get() -> first();
  return view('backend/client.service',compact('client'));
}

public function updateservice()
{
  $clientUpdate = Input::all();
  $client = Client::where('ClientID','1') -> get() -> first();
  $client ->update($clientUpdate);
  return redirect('backend/client/service');
}

2 个答案:

答案 0 :(得分:0)

您可以使用to代替url

<form ACTION="{{ URL::to('backend/client/updateservice') }}" METHOD="POST" id="form1" name="form1" >

或者

Route::post('backend/client/updateservice',array('uses'=>'Backend\ClientController@updateservice','as'=>'updataService'));

使用route()辅助函数:

<form ACTION="{{ URL::route('updataService') }}" METHOD="POST" id="form1" name="form1" >

答案 1 :(得分:0)

问题出在redirect方法的updateservice选项中。将updateservice方法更改为此

public function updateservice()
{
  $clientUpdate = Input::all();
  $client = Client::where('ClientID','1') -> get() -> first();
  $client ->update($clientUpdate);
  return redirect('backend/client/editservice');
}

因为重定向时无法找到重定向路径