我在Eloquent中有两个连接的表,分别是主题和用户。
主题模型:
public function user() {
return $this->belongs_to('User');
}
用户模型:
public function themes() {
return $this->has_many('Theme');
}
我的Eloquent api调用如下:
return Response::eloquent(Theme::with('user')->get());
使用如下代码可仅从用户模型中获取“username”列:
``` Theme.objects.values('user__username') ```
需要注意的是,“user”是外键字段名,应该根据具体情况进行调整。