【发布时间】:2017-04-17 07:47:21
【问题描述】:
我的数据库中有两个表。
Users
id,name
Posts
id,user_id,name
// user_id is the id who has created the post.
How do i get list of all users that have created the posts.
Relation in users table is like this.
=> user HasMany posts.
The relation in Post Class
=> post belongsTo users.
What i have tried so far
$uses = User::with('posts')->get();
This returns list of all users,that has not even created the post
我需要为此更新或创建新关系吗?
【问题讨论】:
-
你为什么投反对票,信息不明确吗?或者这个问题没有意义。
标签: laravel-eloquent