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

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

WBOY
Release: 2016-06-06 20:37:34
Original
1367 people have browsed it

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

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

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

回复内容:

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

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template