/** * Handle the dma.friends.reward.redeemed event * @param Reward $reward * The reward model that has just been redeemed * @param User $user * The user that redeemed the reward */ public function onRewardRedeemed($reward, $user) { $data = ['reward' => $reward, 'user' => $user]; // Send an email to the user that redeemed the reward if ($reward->enable_email) { Mail::send($reward->email_template, $data, function ($message) use($reward, $user) { $message->to($user->email, $user->full_name); }); } if ($reward->enable_admin_email) { Mail::send($reward->admin_email_template, $data, function ($message) use($reward, $user) { // If a group is configured email those users if (!empty($reward->admin_email_group)) { $group = UserGroup::find($reward->admin_email_group); foreach ($group->users as $user) { $message->to($user->email, $user->first_name . ' ' . $user->last_name); } } // If an individual email is configured email that person if (!empty($reward->admin_email_address)) { $message->to($reward->admin_email_address, 'Anonymous'); } }); } // Print the reward if user is at a kiosk $location = LocationManager::getLocation(); if ($location) { $printManager = new PrintManager($location, $user); $printManager->printCoupon($reward); } }