carlek
2 years ago
19
17
Laravel

Laravel 5.4MassAssignmentException in Model.php line 225: _token

Posted 2 years ago by carlek

I was making a system wherein only administrator can adding users. I have a problem, becouse after filling the form I receives error who looks like : MassAssignmentException in Model.php line 225: _token

My Form:

           {!! Form::open(['url'=>'adminpanel/adduser/store','class'=>'form-horizontal']) !!}
            <div class="form-group">
                <div class="col-md-4 control-label">
                    {!! Form::label('nameandsurname','imie i nazwisko:') !!}
                </div>
                <div class="col-md-6">
                    {!! Form::text('nameandsurname', null, ['class' => 'form-control']) !!}
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-4 control-label">
                    {!! Form::label('PESEL','PESEL:') !!}
                </div>
                <div class="col-md-6">
                    {!! Form::text('PESEL',null,['class'=>'form-control']) !!}
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-4 control-label">
                    {!! Form::label('adress','adres:') !!}
                </div>
                <div class="col-md-6">
                    {!! Form::text('adress',null,['class'=>'form-control']) !!}
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 control-label">
                    {!! Form::label('position','stanowisko:') !!}
                </div>
                <div class="col-md-6">
                    {!! Form::text('position',null,['class'=>'form-control']) !!}
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 control-label">
                    {!! Form::label('email','email:') !!}
                </div>
                <div class="col-md-6">
                    {!! Form::text('email',null,['class'=>'form-control']) !!}
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 control-label">
                    {!! Form::label('leavesdays','liczbadniwolnych:') !!}
                </div>
                <div class="col-md-6">
                    {!! Form::text('leavesdays',null,['class'=>'form-control']) !!}
                </div>
            </div>


            {!! Form::hidden('password', null) !!}
            {!! Form::hidden('remember_token',null) !!}

This is User Model :

        use Notifiable;
    
protected $fillable = [
    'nameandsurname', 'email','PESEL','adress','position','leavesdays',

];
protected $table = 'users';

protected $hidden = [
 'password', 'remember_token',
];

Request in controller :

       public function store(AddUserRequest $request)
       {
      //        User::create($request->except('_token'));
$newUser = User::create($request->all());
$newUser->save();

return redirect('/adminpanel/admindashboard');

} Migration:

        public function up()
    {
        Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('nameandsurname',40);
        $table->string('PESEL',9);
        $table->string('adress',30);
        $table->enum('position',array('employer','worker','accountant'));
        $table->string('email',100)->unique();
        $table->string('password');
        $table->integer('leavesdays');
        $table->rememberToken();
        $table->timestamps();
        });
    }

I was looking for this problem on the internet, but any suggestion helped me.

Please sign in or create an account to participate in this conversation.