public function withdrawals() { $withdrawals = []; foreach (Withdrawal::all() as $withdrawal) { if ($withdrawal->orderlinesForUser($this)->count() > 0) { $withdrawals[] = $withdrawal; } } return $withdrawals; }
/** * Send an e-mail to all users in the withdrawal to notice them. * * @param $id Withdrawal id. * @return \Illuminate\Http\RedirectResponse */ public function email(Request $request, $id) { $withdrawal = Withdrawal::findOrFail($id); if ($withdrawal->closed) { $request->session()->flash('flash_message', 'This withdrawal is already closed so e-mails cannot be sent.'); return Redirect::back(); } foreach ($withdrawal->users() as $user) { $data = ['name' => $user->name, 'email' => $user->email, 'date' => $withdrawal->date]; Mail::queue('emails.omnomcom.withdrawalnotification', ['user' => $user, 'withdrawal' => $withdrawal], function ($message) use($data) { $message->to($data['email'], $data['name'])->from('treasurer@' . config('proto.emaildomain'), config('proto.treasurer'))->subject('S.A. Proto Withdrawal Announcement for ' . date('d-m-Y', strtotime($data['date']))); }); } $request->session()->flash('flash_message', 'All e-mails have been queued.'); return Redirect::back(); }