Laravel 4.1 _token error on form submit
Asked Answered
M

1

6

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 :)

Mono answered 11/3, 2014 at 14:25 Comment(1)
Post your controllers code, plz... I think I know what is wrong.Visible
S
17

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

Spirit answered 11/3, 2014 at 15:22 Comment(1)
You are right :) and perfect. i fix it after comparing that specific model with others model. was about to answer my question but your come first :)Mono

© 2022 - 2024 — McMap. All rights reserved.