【发布时间】:2017-09-22 19:20:23
【问题描述】:
我使用 jenssegers 的 Laravel MongoDB 包和 Eloquent Laravel 模型。
文章:
- _id (ObjectID)
- feed_id
- 标题
供稿:
- 身份证
- user_id
- 姓名
用户:
- 身份证
- 姓名
hasManyThrough 在 User::class 模型中获取一个用户的所有文章。
public function articles()
{
return $this->hasManyThrough(
'App\Article',
'App\Feed',
'user_id', // Foreign key on feeds table...
'feed_id', // Foreign key on articles table...
'_id', // Local key on users table...
'id' // Local key on feeds table...
);
}
我通过这个查询只得到 _id (ObjectID):
$user = \App\Models\User::find(1);
dd($user->articles);
你能帮我搜索一下问题吗?
【问题讨论】:
标签: php mongodb laravel eloquent laravel-5.5