在Laravel,关系with->profiles()和->profiles有什么区别?
发布于 2018-11-30 05:04:59
->profiles返回相关模型的集合
->profiles()返回关系的一个实例,如果您想要更新相关的模型,这个实例非常方便。
发布于 2018-11-30 04:55:45
示例:
$posts = $user->posts; // model -> collection
$posts = $user->posts()->get(); // model -> relation -> collection在这里阅读更多信息:https://laracasts.com/discuss/channels/eloquent/dynamic-property-vs-method-in-eloquent-orm
https://stackoverflow.com/questions/53551317
复制相似问题