Laravel-隐藏模型属性



是否有一种方法可以将模型的属性(例如表,连接,主键等(隐藏在Laravel集合中,并且仅保留表的属性/列?

                        [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()

最新更新