Laravel 4 eloquent Mass assignment error in fillab

2019-08-06 01:59发布

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.

2条回答
时光不老,我们不散
2楼-- · 2019-08-06 02:21

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

查看更多
啃猪蹄的小仙女
3楼-- · 2019-08-06 02:36

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.

查看更多
登录 后发表回答