到目前为止,我只是想通过单击按钮来更改数据库记录的状态:
视图
<td>
<a class="btn btn-small btn-warning" href="{{ URL::to('brands/'.$value->BrandID.'/archive') }}">Archive </a>
</td>
控制器
public function archive($id)
{
$rules= array ('BrandName' =>'required | max:20',);
$validator = Validator::make(Input::all(), $rules);
if($validator->fails())
{
return Redirect::to('brands.view')
->withErrors($validator);
} else {
DB::table('tbl_brands')->where('BrandID' , $id)
->update(
array
(
'Status' => 'Archived'
));
Session::flash('message','Successfully Archived!');
return Redirect::to('brandsview');
}
}
和路线
Route::put('brands/{id}/archive', array('as' => 'Brandarch', 'uses'=>'BrandsController@archive'));
和我的错误是什么方法异常。我向下滚动了一下,发现在错误中,http请求是“ get”,我知道应该对如何正确执行此操作“提出”任何想法?
您需要将超链接更改为带有名称为_method
且具有隐藏字段的表单中的提交表单,只有这样您才可以控制所使用的HTTP方法。
例如:
<form action="{{ URL::to('brands/'.$value->BrandID.'/archive') }}" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" value="Archive">
</form>