I have a contact form on my site. When a user submits the form I would like to send an email to all the "site owners". I have the user roles relationships setup and that works fine. I have no issues querying the Owners but I can't seem to send an email to that collection. Here's my code
Are you separating the group emails with a comma? Also, that box means empty array of data. An array of data is required for the 2nd argument. Please post your code for ContactFormSubmitted.
The $user variable is returning an empty array. Are you sure your query is correct? You can pass the to method a collection of users, but it seems like your query is wrong.
if I run that query and dd the output I get a collection of users as a result. Now granted the collection seems to be buried a few levels down the dumped results. Maybe i'm not calling the collection correctly. Should it be
I'm a bit confused. How did you end up with a collection? Are you using query builder? Where is the code that connected the returned dataset to a collection? I think you may be confusing the terms which creates a huge difference in approaching the problem.
If you grab that dataset and make a new collection out of the nested array that you need, I think that will solve your issue. If its already a collection from query builder or eloquent, you can flatten the multi-dimensional array with the flatten() method. This method works on Laravel Collections.
@ejdelmonico I think you're right. I'm returning an eloquent result but the data I'm looking for is nested deep in the returned results. I need to extract that and use that collection.