【发布时间】:2018-02-27 21:31:38
【问题描述】:
美好的一天。在 laravel 中使用 with() 函数时是否可以使用别名?举个例子:
$posts = Post::where(/*condition*/)->with('user as friend')->get();
【问题讨论】:
-
一个帖子可以有很多朋友还是只有一个?
-
$post->user和$post->friend是两个不同的结果。但我已经创建了一个检查if ($post->friend->id == ?)的函数,我试图避免与它重复:if ($post->user->id == ?) -
我不确定我是否理解,您已经为
friend定义了关系,但结果与user不同?