You need to set the $fillable
variable on the model to let it know which fields can be Mass Assigned.
Update:
as deczo and har2vey have stated you can also use $guarded
as a blacklist instead of $fillable
as a whitelist.
문제
Why the first code work, but the second code doesn't work?
First:
$user = new User;
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = Hash::make( Input::get('password') );
$user->save();
Second:
User::create(array(
'name' => Input::get('name'),
'email' => Input::get('email'),
'password' => Hash::make( Input::get('password') ),
));
Error message:
Illuminate \ Database \ Eloquent \ MassAssignmentException
name
해결책
You need to set the $fillable
variable on the model to let it know which fields can be Mass Assigned.
Update:
as deczo and har2vey have stated you can also use $guarded
as a blacklist instead of $fillable
as a whitelist.
다른 팁
For a simpler solution especially if you have no fields to guard, use $guarded instead:
//On top of your model class
protected $guarded = array();