Getting Unique Subscribers Through Consolidation
I will try to explain this using Lists instead of the Adressbook , because I could not understand your model and what could lead to further confusion.
If I understand your comments correctly, you are trying to get all unique subscribers that have associations with id IN listarray . In this case, Eager Loading is not suitable for this. The desired download serves to preload the associations for the model so that they can be used later. In your case, you do not extract the Lists and their Subscribers , but the unique Subscribers themselves.
$lists = Input::get('listsarray'); $subscribers = Subscriber::join('list_subscriber', 'list_subscriber.subscriber_id', '=', 'subscribers.id') ->whereIn('list_subscriber.list_id', $lists) ->groupBy('list_subscriber.subscriber_id') ->get(array('subscribers.*'));
If you also want to get all the lists associated with such subscribers, you can do this:
Lively Download
If it is simply a matter of increasing productivity, you do not need to use different ones, Laravel already does this. Eloquent behaves like this:
- Selects all
Lists . - Iterate through
Lists creating an array of unique list_ids - Selects all
list_subscribers with WHERE list_id IN (X, Y, Z) - Iterate through all
list_subscribers building an array of unique subscriber_id - Selects all
Subscribers using WHERE id IN (X, Y, Z)
source share