[英]Laravel 4 eloquent Mass assignment error in fillable
I'm currently studying eloquent of L4
and I encountered this mass assignment. 我目前正在研究L4
口才,并且遇到了这一大规模任务。 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. 我将按照说明进行操作,并且我知道您需要设置$fillable
才能使用create
方法,但是我仍然在数据库中收到空白行。 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 我也做了: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. 但是结果还是一样。
导致此错误的错误,请参阅https://github.com/laravel/framework/issues/1548现在应修复,运行composer update
以获取最新版本的laravel/framework
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 : 如果您正在使用其他Model,您还可以指定表名:
public $table = ‘users’
This is working fine after run composer update on the root of project directory. 在项目目录的根目录上运行composer update后,此方法运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.