public function updateAndQueue($subject, $body, $notificationType, $action) { // Get the emails that are applicable to this subscription and update them Email::where('status', 'Held')->whereHas('notification.notificationType', function ($q) use($notificationType, $body, $subject) { $q->where('name', $notificationType); })->update(array('content' => $subject, 'body' => $body, 'status' => $action)); // Get the email subscriptions which do not have a corresponding email and create them $notificationsWithNoCorrespondingHeldEmail = Notification::whereHas('notificationType', function ($q) use($notificationType) { $q->where('name', $notificationType); })->whereDoesntHave('emails', function ($q) { $q->where('status', '=', EmailStatus::Held); })->get(); $notificationsWithNoCorrespondingHeldEmail->emails()->save(new \Email(array('subject' => $subject, 'body' => $body, 'status' => $action))); }
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')); }
public function run() { Notification::create(array('user_id' => 1, 'notification_type_id' => 1)); }