MethodNotAllowedHttpException laravel-4 [英] MethodNotAllowedHttpException laravel-4

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

问题描述

形式:

{{ Form::open(array('url' => 'user/create', 'files' => true)) }}

路线:

Route::resource('user', 'UserController');

UserController.php

UserController.php

  class UserController extends BaseController {

    public function index()
    {
        return 'hi11';
        //return View::make('home.index');
    }
    public function create()
    {
        return 'hi22';
        //return View::make('home.index');
    }

}

此代码给出

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

推荐答案

我只想添加我自己的发现沿着这些路线...也许这会保存别人头痛我刚刚执行。

I'd just like to add my own discovery along these lines... Maybe this will save someone else the head-scratching I just performed.

我太实现了Route :: resource机制。我不知道为什么我的创建工作,但我的更新没有。原来你不能正确地重复使用相同的表单代码,执行更新的表单必须使用PUT或PATCH方法。为什么更新不能是一个POST是超出我的。

I too implemented the Route::resource mechanism. I couldn't figure out why my create was working but my update was not. It turns out you can't reuse the same form code exactly, the form that does an update must use the method PUT or PATCH. Why update couldn't be a POST is beyond me.

也就是说,更新的开放表单标签应如下所示:

That is to say, the opening form tag for an update must look like this:

Form::model($thing, array(
    'method' => 'PUT', 
    'route' => array('things.update', $thing->id)
    )

没有指定方法=> PUT,你会得到这个无用的错误。

Without specifying method => PUT, you get this not-helpful error.

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

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