Regarding your error
You just have a PHP syntax error. Here's the code you want:
// This function uses the parameters $data that is passed to this function each time
// the fire() function loops through and assigns and determines that there is a duereport
private function sendGeneralManagerEmail($data)
{
// create an array called 'Park' that is poulated via the $data parameters
// in the function and is specificly looking for the ParkName entries
$data['Park'] = $Park->ParkName;
//for each item in that array use $ParkName as a key and name each elements $name
foreach($data['Park'] as $ParkName => $name)
{
// Every time i loop through this file get the element $name and
// attach this prefix to it
$email = $name."generalmanager@parkholidays.com";
}
// Then send an email with new $email variable as a reciepient and sending the $data passed
// from the fire() function and used within this functions parameters
Mail::send('emails.GeneralManager', $data, function($message) use ($email)
{
$message->to( $email, 'General Manager')->subject('[Urgent] Health & Safety Reports');
});
}
See the use $email
you had that I've changed to use ($email)
in the closure at the end.
Regarding your more general question about coding
I can see a few things that don't look right to me. Is this code an exact replica of the function or have you removed some code?