Issue
A user(employer) have many posts and many user(employee) can apply these posts . Point is employer should get which users applied for each its posts.
Simply want to get applicants for each posts for each employer id.
I tried $employees = Post::find(//anyNumber//)->people;
it gives proper applicants infos but it should be dynamic for each employer user .
Tables..
applies -> | users_id(employee) | posts_id |
posts -> | id | user_id(employer) | (other posts cols ... )
user_info -> | id | (name col etc... for employee)
Post Model..
public function people()
{
return $this->belongsToMany(Info::class , 'applies', 'user_id' , 'posts_id');
}
Controller..
public function index()
{
$user_id = Auth::id();
$myPosts = Post::where('user_id',$user_id)->get();
$employees = Post::find(//anyNumber//)->people; // this line
dd($employees);
}
Solution
If I understand the question correctly, you are looking for all the employees who applied for the post of the employer. You should be able to pull all those "People" in the same query you get your posts from using the "with" statement.
For example:
$myPosts = Post::where('user_id', $user->id)->with('people')->get();
Answered By - Dan Castanera
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.