MethodNotAllowedHttpException

MethodNotAllowedHttpException

本文介绍了Laravel 5.1使用资源控制器的存储方法上的MethodNotAllowedHttpException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用资源控制器将记录添加到数据库,但是,出现MethodNotAllowedHttpException错误.我已经遇到过类似的问题,例如 this 或,但是,似乎没有人回答我.这是我的代码:

I am trying to add a record to a database utilizing a resource controller, however, am getting MethodNotAllowedHttpException error. I have gone through several similar questions like this or that ,however, none seem to answer me. This is my code:

Routes.php

Routes.php

Route::resource('animals', 'AnimalsCtrl');

我的模型的一部分.

protected $table='animals';
protected $primaryKey='name';

protected $fillable = [
    'name', 'type'
];

控制器中的存储方法.

   public function store(Request $request)
    {
        $creature = $request->all();
        Animal::create($creature);

    }

这是表格.

        <form method="post">
            <div class="small-6 small-centered large-4 large-centered columns">
                {!! csrf_field() !!}
                <table>
                    <tr>
                        <th scope="row">Name</th>
                        <td>
                            <input type="text" name="name" maxlength="50" required>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Type</th>
                        <td>
                            <input type="text" name="type" maxlength="20" required>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <button type="submit" class="button success">
                                <i class="fi-plus"></i>
                                Add Animal
                            </button>
                        </th>
                        <td>
                            <a href="{{url('/animals')}}" class="button alert">
                                <i class="fi-x-circle"></i>
                                &nbsp; Cancel
                            </a>
                        </td>
                    </tr>
                </table>
            </div>
        </form>

有人对我如何解决这个问题有任何建议吗?

Does anyone have any suggestion on how I can resolve this?

推荐答案

发布表单时,将表单发布到的URL是什么?网址应该在action中.例如如下

When you are posting the form, what is the URL that you are posting the form to ? The url should be in the action . For example as follows

<form action="/animals" method="post">
</form> 

这篇关于Laravel 5.1使用资源控制器的存储方法上的MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 05:25