Laravel中的关系with->profiles()
和->profiles
有什么区别?
答案 0 :(得分:4)
->profiles
返回相关模型的集合
->profiles()
返回关系的一个实例,如果您想更新相关模型,该实例非常方便
答案 1 :(得分:1)
示例:
$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