我是laravel的新手,它创建了一条路由并为其提供了一个控制器,该控制器具有一种更新数据库的方法..但是一旦它读取了该路由,应用程序便无法到达该控制器
Route::post('/workorder/store/third/{$id}',
[
'uses'=>'WorkOrdersController@storeThird',
'as'=>'workorder.store.third'
]);
//method in WorkOrderController
public function storeThird(Request $request,$id)
{
$this->validate($request,[
'address_region'=>'required|string',
'address_no'=>'required|string',
]);
$workorder = WorkOrder::find($id);
$workorder->address_region = $request->address_region;
$workorder->address_no = $request->address_no;
$workorder->save();
return view('third-workorder',compact('workorder'));
}
浏览器结果... 在地址栏中。.“ http://localhost:8000/workorder/store/third/9” 并在浏览器中..“对不起,找不到您要查找的页面。”
这个.. view.blade看起来像
<div class="modal" id="createThirdWorkshopModal">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="{{ route('workorder.store.third',['id'=>$workorder->id]) }}" >
{{ csrf_field() }}
答案 0 :(得分:0)
在浏览器中直接导航到http://localhost:8000/workorder/store/third/9
是一个 GET
请求,但是您将路由定义为处理 POST
的路由请求。您需要提交一些信息以使该路线“被找到”:
<form method="POST" action="{{ url("/workorder/store/third/".$id) }}" ...>
...
</form>
或将路线定义为
Route::any("/workorder/store/third/{$id}", ...);
来解决这个问题。
注意:::any()
处理所有HTTP动词(GET
,POST
,PUT
,DELETE
等)
答案 1 :(得分:0)
Router::post('/workorder/store/third/{$id}', WorkOrdersController@storeThird)->name('workorder.store.third');
并使用:
<a href="{{route('workorder.store.third', $id)}}">
...
</a>