[英]Laravel mass assignment won't fill fields
我有一個似乎不是大規模可分配的模型,即使我填寫了$fillable
字段:
class LoginAttempt extends Eloquent
{
protected $table = 'login_history';
protected $fillable = array('remote_addr', 'user_agent', 'successful');
public function user()
{
return $this->belongsTo('User');
}
}
哪個使用此架構:
當我使用這些變量批量分配實例時,
$vars = array(
'remote_addr' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
'successful' => false,
);
print_r($vars);
=> array('remote_addr' => '127.0.0.1', 'user_agent' => 'Moz..', 'successful' => false);
new LoginAttempt($vars);
=> LoginAttempt instance, attributes => array()
LoginAttempt::create($vars);
=> LoginAttempt instance, attributes => array()
$login = new LoginAttempt;
$login->fill($vars);
=> LoginAttempt instance, attributes => array()
$login = new LoginAttempt;
$login->remote_addr = $vars['remote_addr'];
$login->user_agent= $vars['user_agent'];
$login->successful= $vars['successful'];
=> LoginAttempt instance, attributes => array('remote_addr' => '..', 'user_agent' => '..', 'successful' => false)
我認為我正在使用$fillable
作為文檔描述 - 為什么在這種情況下批量作業不起作用?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.