表单提交时 Laravel 4.1 _token 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22328629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:09:46  来源:igfitidea点击:

Laravel 4.1 _token error on form submit

phpformslaravellaravel-4csrf-protection

提问by Dexture

I am doing simple cms in laravel 4.1 , i created many form and they working fine, but the last form which i create throws error on submit.

我正在 Laravel 4.1 中做简单的 cms,我创建了许多表单并且它们工作正常,但是我创建的最后一个表单在提交时抛出错误。

Illuminate \ Database \ Eloquent \ MassAssignmentException
_token

The data posted by form also show on error page.

表单发布的数据也显示在错误页面上。

_token  KLlDjuFgaEmuGHKMpFjqSrukYT3sawOYYZLPGxnb
name    asdf
body    asdfasdfa
bio sdfasdf

So its mean the _token is also posted then why i am getting this error.

所以它的意思是 _token 也被发布了,那么为什么我会收到这个错误。

My form look like this.

我的表格看起来像这样。

{{ Form::open(array('route' => 'admin.teachers.store','files'=>true)) }}
    <ul>
        <li>
            {{ Form::label('image', 'Image:') }}
            {{ Form::file('image') }}
        </li>

        <li>
            {{ Form::label('name', 'Name:') }}
            {{ Form::text('name') }}
        </li>

        <li>
            {{ Form::label('body', 'Body:') }}
            {{ Form::textarea('body',null,array('class'=>'ckeditor')) }}
        </li>

         <li>
            {{ Form::label('bio', 'Bio:') }}
            {{ Form::textarea('bio',null,array('class'=>'ckeditor')) }}
        </li>



        <li>
            {{ Form::submit('Submit', array('class' => 'btn btn-info')) }}
        </li>
    </ul>
{{ Form::close() }}

I see one related question to _tokenissue on forum but it didn't help me.

我在论坛上看到一个与_token问题相关的问题,但对我没有帮助。

Thanks in advance :)

提前致谢 :)

回答by Antonio Carlos Ribeiro

In fact your error is MassAssignmentException, which means that you are using

事实上你的错误是MassAssignmentException,这意味着你正在使用

Model::create($input);

In your controller and not using

在您的控制器中而不是使用

protected $fillable = array('columnA', 'name'...);

or

或者

protected $guarded = array();

In your Model, to tell Laravel which fields of your table are mass assignable.

在您的模型中,告诉 Laravel 表的哪些字段是可批量分配的。

Take a look at the docs: http://laravel.com/docs/eloquent#mass-assignment

看看文档:http: //laravel.com/docs/eloquent#mass-assignment