Reputation: 2775
I'm currently studying eloquent of L4
and I encountered this mass assignment. I'd follow the instructions and I know you need to setup your $fillable
to use the create
method but I am still receiving a blank row in the database. here's my code:
MODEL:
class User extends Eloquent
{
protected $fillable = array('email','pwd','active','name');
}
CONTROLLER:
$user = new User;
$add = array(
'name'=>Input::get('custname'),
'active'=>1,
'pwd'=>Hash::make(Input::get('pwd')),
'email'=>Input::get('email')
);
return var_dump($user->create($add));
I also did: CONTROLLER
$add = array(
'name'=>Input::get('custname'),
'active'=>1,
'pwd'=>Hash::make(Input::get('pwd')),
'email'=>Input::get('email')
);
return var_dump(User::create($add));
But still the same result.
Upvotes: 1
Views: 3640
Reputation: 4885
Yes with new version you can use public or protected keywords.
Simple use this :
protected $fillable = [‘email’, ‘pwd’,’active’,’name’];
You can also specify table name if you are working with other Model like this :
public $table = ‘users’
This is working fine after run composer update on the root of project directory.
Upvotes: 0
Reputation: 812
There was a bug causing this, see https://github.com/laravel/framework/issues/1548
Should be fixed now, run composer update
to get the newest version of laravel/framework
Upvotes: 1