【发布时间】:2018-02-20 02:09:07
【问题描述】:
有没有办法在 Laravel 集合中隐藏模型的属性,例如表、连接、primaryKey 等,并且只保留表的属性/列?
[table:protected] => product
[connection:protected] => mysql
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[withCount:protected] => Array
(
)
[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
...
)
[original:protected] => Array
(
...
)
...
)
【问题讨论】:
-
如果您愿意,请致电
->toArray()收集收藏 -
隐藏它们以防什么?如果您希望它们从 JSON 响应中隐藏,请在模型中使用
protected $hidden = ['foo'];来隐藏属性。 laravel.com/docs/5.6/…