首页 > 解决方案 > 405方法不允许重定向错误laravel为什么

问题描述

我的删除功能是这样的:

在我添加此行之前帮助我return Redirect::route('attribute.index');

我没有错误,但是在我有这个错误之后

405 方法不允许

public function update($id)
{
    $input = Input::all();
    $validator = Validator::make($input, CapacityModel::rules());

    // process the save
    if ($validator->fails()) {
        Session::flash('message', trans('messages.error_save'));
    } else {
        // store
        $this->capacity->update($input['capid'], $input);

        // redirect
        Session::flash('message', trans('messages.success_save'));
        return Redirect::route('attribute.index');
    }
}

我的路线是这样的:

Route::resource('/reference/attribute','nez\attribute\SeiAttributeController',['names'=>'attribute']);

我的控制器的索引是这样的:

public function index()
{
    return View::make($this->view_path.'.index');
}

标签: phplaravel

解决方案


这看起来很可疑:

  $this->capacity->update($input['capid'], $input);

在哪里$this->capacity得到解决?您确定该属性始终在方法中设置吗?

update 方法通常采用单个参数,该参数是具有新值的键数组。

如果您已将 $this->capacity 正确解析为要更新的记录,那么您最好使用以下内容:

$this->capacity->update([
    'field_1' => Arr::get($input, 'field_1'),
    'field_2' => Arr::get($input, 'field_2'),
     //...etc
]);

推荐阅读