如何获取已创建帖子的所有用户的列表
How to get list of all users that have created the posts
我的数据库中有两个表。
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.Have 看看这个 URL
顺便说一句,你可以试试这个。
$users = User::has('posts')->get();
它将 return 列出所有有帖子的用户。
我的数据库中有两个表。
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.Have 看看这个 URL
顺便说一句,你可以试试这个。
$users = User::has('posts')->get();
它将 return 列出所有有帖子的用户。