看源码的注释,$hidden 定义的属性在被 序列化 的时候会被隐藏。
文档解释:https://laravel.com/docs/5.5/eloquent-serialization#hiding-attributes-from-json
当需要对用户密码或其它敏感信息在用户实例通过数组或 JSON 显示时进行隐藏,则可使用 hidden 属性。
Laravel 模型中 $hidden 的作用
打印测试:
Laravel 模型中 $hidden 的作用
Laravel 模型中 $hidden 的作用
从打印效果可以看到,把数据序列化为 JSON 格式后,$hidden 设置的字段是不会显示的。再看模型实例的打印效果中, hidden 数组中包括模型中设置的字段。

相关文章:

  • 2023-03-19
  • 2021-10-02
  • 2022-02-10
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案