Home  >  Article  >  Backend Development  >  有关Laravel中eloquent fillable和guard属性的作用

有关Laravel中eloquent fillable和guard属性的作用

WBOY
WBOYOriginal
2016-06-06 20:37:341317browse

最近正在学习Laravel,用的4.2的版本,在学习Eloquent时然后写了一下例子看到两个属性,Google了一下还是没怎么理解想请问一下以下代码中

<code>...
    protected $guard = array('email','password');
    protected $fillable = array('nickname','email','password');
    protected $hidden = array('password', 'remember_token');
...
</code>

其中的三个属性各有什么样的作用?

回复内容:

最近正在学习Laravel,用的4.2的版本,在学习Eloquent时然后写了一下例子看到两个属性,Google了一下还是没怎么理解想请问一下以下代码中

<code>...
    protected $guard = array('email','password');
    protected $fillable = array('nickname','email','password');
    protected $hidden = array('password', 'remember_token');
...
</code>

其中的三个属性各有什么样的作用?

前两者为 自动填充 Mass Assignment 的黑名单和白名单。第三者为 转换成数组或 JSON 时隐藏属性。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn