Laravel-在集合中隐藏模型属性

Laravel-在集合中隐藏模型属性,laravel,eloquent,Laravel,Eloquent,有没有办法在Laravel集合中隐藏模型的属性,如表、连接、primaryKey等,并仅保留表的属性/列 [table:protected] => product [connection:protected] => mysql [primaryKey:protected] => id [k

有没有办法在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
                            (
                                ...
                            )
                       ...
                    )

您不需要这样做,因为这些是雄辩的模型对象的属性,当您序列化对象或将其转换为JSON或数组时,它们将被忽略:

$model->toArray()

如果您想从何处删除它们,请对集合调用
->toArray()
?如果您想从JSON响应中隐藏它们,请使用
protected$hidden=['foo']以隐藏属性。我试过了,但是我失去了模型的关系。。有没有办法保存这些关系?@InoveCommerc加载的关系数据仍然存在,但它将是一个多维数组,而不是一个集合。