public function queue($subject, $body, $notificationType, $action) { $notificationsToQueueEmailsFor = Notification::where('notification_type_id', $notificationType)->get(); foreach ($notificationsToQueueEmailsFor as $notification) { $email = new Email(); $email->notification()->associate($notification); $email->subject = $subject; $email->body = $body; $email->status = $action; $email->save(); } }
public function editSMSNotifications($username) { $user = User::where('username', $username)->with('notifications.notificationType')->firstOrFail(); $sms = Input::get('SMSNotification'); // Delete any previous SMS notification Notification::where('user_id', $user->user_id)->whereIn('notification_type_id', [NotificationType::TMinus24HoursSMS, NotificationType::TMinus3HoursSMS, NotificationType::TMinus1HourSMS])->delete(); // If the number is blank, assume the user wants their SMS setup deleted if ($sms['mobile'] == "") { $user->resetMobileDetails(); $user->save(); return response()->json(Lang::get('profile.sms.succeeded')); } // If status is not false if ($sms['status'] != 'false') { // Because Twilio $client = new Lookups_Services_Twilio(Config::get('services.twilio.sid'), Config::get('services.twilio.token')); // Try to see if the number exists, if not, will throw exception try { $number = $client->phone_numbers->get($sms['mobile']); // Check for errors if (!isset($number->status)) { // Set user mobile details $user->setMobileDetails($number); $user->save(); // Insert new notification Notification::create(array('user_id' => Auth::id(), 'notification_type_id' => NotificationType::fromString($sms['status']))); return response()->json(Lang::get('profile.sms.succeeded')); } return response()->json(Lang::get('global.somethingWentWrong'), 500); } catch (Services_Twilio_RestException $e) { return response()->json(Lang::get('profile.sms.failed'), 400); } } return response()->json(Lang::get('profile.sms.succeeded')); }