0

I have Project Model each Project has Many Positions from Position Model and each positions has Many Employees in Employee Model

Now I want to query all employees id's of the particular project regardless their position,

How can I achieve this using eloquent?

3
  • 2
    Take a look at this. Commented May 9, 2019 at 8:54
  • I think your question is well described, but at stackoverflow you will need to have the code you tried to solve it with included and or some steps to reproduce your problem, your question is very abstract and for future reference you will need to include more :) Commented May 9, 2019 at 9:04
  • That was helpful @nakov Commented May 10, 2019 at 15:29

2 Answers 2

1

Roughly you would do something similar to this, where you can use whereHas to create nested queries on relations.

$employeeIdsToFilter = [1,2,3];

$filteredProjects = Project::query()->
    whereHas('positions' , function ($query) use ($employeeIdsToFilter) {
        $query->whereHas('employees', function($query) use ($employeeIdsToFilter) {
            $query->whereIn('id', $employeeIdsToFilter);
        });
    })->get();
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the HasManyThough relation. Here is the Link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.