这是我正在使用的路线
Route::match(['get','post'],'/admin/editCategory/{id}', 'CategoryController@editCategory');
我在控制器中的编辑功能是
public function editCategory(Request $request, $id=null){
if ($request->isMethod('post')){
$data = $request->all();
Category::where(['id'=>$id])->update(['name'=>$data['category_name'],'description'=>$data['cat_description'],'url'=>$data['category_url']]);
return view('admin/categories/view_categories')->with('flash_message_success','Category updated successfully!');
}
$categoryDetails = Category::find($id);
// $levels = Category::where(['parent_id'=>0])->get();
return view('admin/categories/editCategory')->with(compact('categoryDetails','id'));
}
这是我的编辑表格
<form data-toggle="validator" action="{{ action('CategoryController@editCategory',$categoryDetails->id) }}" class="form-horizontal" id="add_category" name="add_category" method="POST" novalidate="nonvalidate">@csrf
<input name="_method" type="hidden" value="PUT">
<div class="form-group">
<label for="category_name" class="control-label col-sm-3">Category Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="category_name" name="category_name" required value="{{ $categoryDetails->name }}">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label for="cat_description" class="control-label col-sm-3">Description</label>
<div class="col-sm-6">
<textarea class="form-control" id="cat_description" name="cat_description" data-error="Category Description is required" required>{{ $categoryDetails->description }}</textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label for="confirm_pwd" class="control-label col-sm-3">URL</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="category_url" name="category_url" data-error="Category URL is required" required value="{{ $categoryDetails->url }}">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-6 col-sm-offset-3">
<button type="submit" name="submit" id="edit_category" class="btn btn-success">Update Category</button>
</div>
</div>
</form>
这是错误 Symfony \组件\ HttpKernel \异常\ MethodNotAllowedHttpException 没有消息