【发布时间】:2022-01-15 22:53:02
【问题描述】:
一个用户(雇主)有很多帖子,很多用户(员工)可以申请这些帖子。重点是雇主应该知道哪些用户申请了每个职位。
只是想为每个雇主 ID 的每个职位获取申请人。
我尝试了 $employees = Post::find(//anyNumber//)->people;,它提供了正确的申请人信息,但对于每个雇主用户来说应该是动态的。
表格..
applies -> | users_id(employee) | posts_id |
posts -> | id | user_id(employer) | (other posts cols ... )
user_info -> | id | (name col etc... for employee)
后模型..
public function people()
{
return $this->belongsToMany(Info::class , 'applies', 'user_id' , 'posts_id');
}
控制器..
public function index()
{
$user_id = Auth::id();
$myPosts = Post::where('user_id',$user_id)->get();
$employees = Post::find(//anyNumber//)->people; // this line
dd($employees);
}
【问题讨论】:
-
我什么都不懂,请您补充更多信息。
标签: php laravel laravel-5 eloquent