Fixed – MassAssignmentException in model.php laravel 5?

Fixed – MassAssignmentException in model.php laravel 5?

In this post we will give you information about Fixed – MassAssignmentException in model.php laravel 5?. Hear we will give you detail about Fixed – MassAssignmentException in model.php laravel 5?And how to use it also give you demo for it if it is necessary.

massassignmentexception is for the security purpose if laravel 5 function. When i did start Laravel 5 and first i did try to add user using “User::create([‘name’=>’hd’,’password’=>’1w’])” then i found bellow error. I was thinking what was wrong, but after investigation i found it for our security purpose, because you have to add field name that you want to insert that way other Http script or hacker etc can’t insert something elelse you need to add $fillable variable in your Model. So, let’s see user model example.

User.php

namespace App;


use IlluminateFoundationAuthUser as Authenticatable;


class User extends Authenticatable

{

/**

* The attributes that are mass assignable.

*

* @var array

*/

protected $fillable = [

'name', 'email', 'password','facebook_id'

];


/**

* The attributes excluded from the model's JSON form.

*

* @var array

*/

protected $hidden = [

'password', 'remember_token',

];


public function dataCreate($input)

{

return static::create($input);

}

}

Hope this code and post will helped you for implement Fixed – MassAssignmentException in model.php laravel 5?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  89  =  97

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US