I have no clue what you are really doing, but based on a basic understanding of Laravel and what it seems like you are trying to do with different "flags" or "criteria", doesn't it make sense to continue adding to the main collection based on each criteria, and then fetch the email addresses once the main collection's query properties are all added in. For example:
// Start with your Account, ordered by ID:
$accounts = Account::orderBy('id');
// if a city ID is provided, add this to the "where" section of the main collection:
if($this->city_id !== NULL) {
$accounts->where('location_id', $this->city_id);
}
// if an Account Type is provided, add this to the "where" section of the main collection:
if ($this->account_type !== NULL) {
$accounts->where('type_id', $this->account_type);
}
// if Premium Only is set, add this to the "where" section of the main collection:
if ($this->only_premium == TRUE) {
$accounts->where('is_premium', $this->only_premium);
}
// if Free Only is set, add this to the "where" section of the main collection:
if ($this->only_free == TRUE) {
$accounts->where('is_premium', $this->only_free);
}
/* For those last two, it's a bit confusing whether only_free and only_premium are mutually exclusive,
so maybe consider having one property that toggles between Free/Premium
(assuming it can't be both but must be one or the other). */
// Finally, pull the emails (the "plucking" off of the final $accounts collection variable:
$emailAccounts = $accounts->get()->pluck('email')->toArray();
I am fairly certain that at least one part of this example code is fundamentally wrong, but that it is also fundamentally more logical and clear for what you are wanting to do.