在 Laravel 中与 ->profiles() 和 ->profiles 的关系有什么区别?



Laravel中的关系with->profiles()->profiles之间有什么区别?

->profiles返回相关模型的集合

->profiles()返回关系的一个实例,如果您想更新相关模型,这很方便

示例:

$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

最新更新