编程语言
首页 > 编程语言> > php – Laravel 4.2删除时的MethodNotAllowedHttpException

php – Laravel 4.2删除时的MethodNotAllowedHttpException

作者:互联网

我是Laravel的新手,所以有一个项目,一个简单的CRUD,但当我尝试删除数据时删除方法不起作用,我真的不知道为什么.这是错误:

错误:

throw new MethodNotAllowedHttpException($others);

控制器:

public function destroy($id)
{
    $project = Project::find($id);
    if($project->user_id==Auth::id()) {
        $project->delete();
        return Redirect::to('/');
    } else {
        Session::flash('message', 'You can't delete this!');
        return Redirect::to('/');
    }
}

视图:

{{Form::open(array('url' => 'project/destroy/'.$p->id, 'method' => 'DELETE'))}}
    {{Form::submit("Delete", array('class' => 't2tButton text-center'))}}
{{Form::close()}}

路线:

Route::post('/project/destroy/{id}', "ProjectController@destroy");

解决方法:

您有一个POST设置的路由,但不是DELETE.

尝试将此添加到您的路线:

Route :: delete(‘/ project / destroy / {id}’,“ProjectController @ destroy”);

或者您可以将方法更改为POST并保持路由不变,但为了保持RESTful,最好更改为DELETE.

标签:laravel-routing,php,laravel,laravel-4
来源: https://codeday.me/bug/20190830/1768536.html