1

I'm rather stuck trying to figure out how I can run this as a single query from the database rather than fetching the results using one query then executing the other.

$query->whereIn('page_user_id', Staff::lists('staff_id'));

Thanks for the help

1 Answer 1

3
$query->join('staff', 'staff.staff_id', '=', 'user.page_user_id')->get();

I think this will help. For reference http://laravel.com/docs/5.1/queries

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for trying, but that's three queries not one
@Shard can you please send me full query So I can provide you correct solution.
I could but the query builder is 150+ lines long and likely wouldn't help you come to a solution. I basically don't want to have to fetch the data Staff::all()->lists('staff_id') then query it. I want a select subquery within my whereIn that deals with the results all in one query from the database.
ok, then you can use laravel join's $query->join('staff', 'staff.staff_id', '=', 'user.page_user_id')->get(); (laravel.com/docs/5.1/queries)
Perfect dude, put that as an answer so I can tick it

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.