我有一个users
表和posts
表与['title', 'body', 'user_id', 'id']
并且只有一对一的关系。Laravel过滤器关系字段
我该如何过滤posts
表,其中只显示body
字段使用它们的关系。
例如
$users = User::with('post')->get();
,其结果将是
[{
'username':'jrsalunga',
'post_id': 1,
'post': {'title': 'sample title'}, // show title only
'id': 2
}]
就像魅力一样!谢谢! – jrsalunga