拉拉维尔隐藏属性。例如:密码 - 安全性
2022-08-30 20:38:34
根据 http://laravel.com/docs/eloquent,可以通过在模型中使用受保护的$hidden变量来隐藏数组或JSON转换中的属性。
class User extends Eloquent {
protected $hidden = array('password');
}
很好,但是,在运行时,加密的密码在User对象内从服务器发送到客户端。print_r(User::all())
这不仅限于print_r(),如果查询特定用户,则会在视图中显示加密的密码。$user->password
有没有办法阻止这种情况?每次查询我的用户对象时,密码都会作为数据的一部分随之发送,即使它不需要。
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => User Object
(
[hidden:protected] => Array
(
[0] => password
)
[connection:protected] =>
[table:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 1
[email] => admin@admin.com
[first_name] => Admin
[last_name] => User
[password] => $2y$10$7Wg2Wim9zHbtGQRAi0z6XeapJbAIoh4RhEnVXvdMtFnwcOh5g/W2a
[permissions] =>
[activated] => 1
[activation_code] =>
[activated_at] =>
[last_login] =>
[persist_code] =>
[reset_password_code] =>
[created_at] => 2013-09-26 10:24:23
[updated_at] => 2013-09-26 10:24:23
)