laravel model显示和隐藏属性

在自己的model下

隐藏字段信息

比如我的密码不能够在查询的时候显示出来

protected $hidden = ['password'];

允许显示的

 protected $visible = ['first_name', 'last_name'];

这里只能设置一个,不能同时,否则只会执行 $visible

临时暴露隐藏属性makeVisible('password')

 $merchant=Merchant::first()->makeVisible('password')->toArray();
       print_r($merchant);

临时隐藏属性makeHidden('password')

$merchant=Merchant::first()->makeHidden('password')->toArray();
       print_r($merchant);

猜你喜欢

转载自blog.csdn.net/weixin_34218890/article/details/88281999