资源定义的方法Laravel-4上的MethodNotAllowedHttpException [英] MethodNotAllowedHttpException on resource defined method Laravel-4

查看:91
本文介绍了资源定义的方法Laravel-4上的MethodNotAllowedHttpException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的表单,以便可以使用提交按钮而不是链接来打开编辑用户页面.使用链接可以完美地工作,但是即使方法("edit")在UsersController资源中已完美定义,并且正常工作,表单按钮也无法通过并产生MethodNotAllowedHttpException.

I created a very simple form so that I could use a submit button rather than a link to open up an edit users page. Using a link works perfectly, but the form button fails and yields a MethodNotAllowedHttpException even though the method ("edit") is perfectly defined in the UsersController resource and otherwise works fine.

路线:

Route::resource('users','UsersController');

UsersController:

UsersController:

public function edit($id)
    {
        $user = $this->user->find($id);
        return View::make('users.edit')->with('user',$user);
    }

show.blade.php:

show.blade.php:

<!-- This works fine: -->
{{ link_to_route('users.edit', ("Edit: " .$user->first_name." ".$user->last_name), $user->id) }}

<!-- This doesn't work, and yields the Method Not Allowed exception: -->
{{ Form::open(array('route' => array('users.edit',$user->id))) }}
{{ Form::submit('Edit User', array('class'=>'button')) }}
{{ Form::close() }}

谢谢.

推荐答案

执行Form::open()时,默认情况下使用post请求方法.但是,当您创建Route::resource()时,edit方法将接受get请求.

When you do Form::open(), it defaults to using the post request method. But when you create a Route::resource(), the edit method takes a get request.

要使其在表单中起作用,您需要使用其他参数将其打开,如下所示:

To make it work through the form, you'll need to open it with an additional parameter, like this:

{{ Form::open(array('route' => array('users.edit',$user->id),
   'method' => 'get')) }}

这篇关于资源定义的方法Laravel-4上的MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆