have you checked that $parent contains what you expect. You are setting it up that $parent must be an array but I did not get that from your description?
Query Help
I am trying to do a query based on these params / conditions.
The site has a database table of "areas" consisting of a nested table of countries / states or regions/ and cities so the user can select Los Angeles ( say area.id = 123) so there is a pivot table called area_profiles that stores profile_id and area_id.
Now when a regular user visits the site and clicks on Los Angeles I want to pull all users (Profiles) in area_id = 123 but with conditions that the profile.complete = true and that area_profiles.active = true (user can have many areas but select to have 1 active at a time)
Query ends up like so:
select profiles., area_profiles. from profiles inner join area_profiles on profiles.id = area_profiles.profile_id where area_profiles.area_id in (123) and area_profiles.active = true and profiles.completed = true
From this query builder:
$profiles= DB::table('profiles')
->join('area_profiles', 'profiles.id', '=', 'area_profiles.profile_id')
->select('profiles.*', 'area_profiles.*')
->whereIn('area_profiles.area_id', $parent)
->where('area_profiles.active', true)
->where('profiles.completed', true)
->get();
But always zero results. I have 50 dummy accounts, all active, completed (marked true) and all set to an area_id of 123.
Basicaly in english I want to say get all profiles when the profile has a record in that area of Los Angeles if that profile is complete and that its an active profile_area.
Anyone see where I am going wrong?
Thoughts? Suggestions?
Thanks,
Dave
Yes $parent is an array of either a single area_id if Los Angeles or a full array of all area_id's if someone clicks on California it pulls all area_id's in California's area_id's.
Its actually working....
My bad I forgot to include an extra parameter in the query.
Thanks all the same for the effort :)
Dave
Please or to participate in this conversation.