Dmitry
Dmitry

Reputation: 27

Database \ Eloquent \ MassAssignmentException fam

I try add data to databese. But have this error.

Illuminate \ Database \ Eloquent \ MassAssignmentException fam

'fam' is a name first argument.

Data dump:

 array:8 [▼
  "fam" => "6"
  "im" => "e"
  "ot" => "r"
  "phone" => "e"
  "log" => "e"
  "pass" => "e"
  "Регистрация" => null
  "_token" => "bEJpcLPYWo5GmhW11Zxs8K0dMmN6anNsvuO0a492"
]

Function code:

  $this->validate($request,[
            'fam'=>'required|max:255',
            'im'=>'required|max:255',
            'ot'=>'required|max:255',
            'log'=>'required|max:255',
            'pass'=>'required|max:255',
            'phone'=>'required|max:255',
            'Регистрацияd'=>'require|max:255'
        ]);
        $data=$request->all();
        dump($data);
        $user=new userModel;
        dump($user);
       $user->fill($data);

User Model dump:

userModel {#192 ▼
  #filable: array:8 [▶]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: []
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}

And model code:

class userModel extends Model
{
    protected $filable=['fam','im','ot','phone','login','pass','reg','token'];

}

You can see the structure of the database here: enter image description here

Upvotes: 1

Views: 650

Answers (1)

user8760162
user8760162

Reputation:

Your model has no attributes, and it looks like you have a typo in $fillable

protected $filable=['fam','im','ot','phone','login','pass','reg','token'];

Upvotes: 1

Related Questions