Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4.1 _token error on form submit

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.

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.

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 _token issue on forum but it didn't help me.

Thanks in advance :)

like image 731
Dexture Avatar asked Mar 11 '14 14:03

Dexture


1 Answers

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

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.

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

like image 78
Antonio Carlos Ribeiro Avatar answered Nov 04 '22 22:11

Antonio Carlos Ribeiro