/**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['unread' => 'boolean']);
     $notification = Notification::findOrFail($id);
     if ($notification->user_id !== Auth::id()) {
         throw new UnauthorizedException();
     }
     $notification->update($request->only('unread'));
     return $notification;
 }
 /**
  * Record a notification for the user but make sure there are no duplicates first
  *
  * @param int    $userId
  * @param string $message
  * @param string $type
  * @param string $hash
  * @return Notification
  */
 public static function logNew($userId, $message, $type, $hash)
 {
     $existingNotifications = Notification::where('user_id', $userId)->where('hash', $hash)->first();
     if ($existingNotifications) {
         return $existingNotifications;
     }
     $newNotification = parent::create(['user_id' => $userId, 'message' => $message, 'type' => $type, 'hash' => $hash]);
     event(new NewMemberNotification($newNotification));
     return $newNotification;
 }
 /**
  * @param integer $id
  * @param integer $userId
  */
 public function declineExpense($id, $userId)
 {
     $expense = $this->model->findOrFail($id);
     $expense->approved = false;
     $expense->declined = true;
     $expense->approved_by_user = $userId;
     $expense->save();
     $message = 'Your expense was declined';
     $notificationHash = $expense->id . '-expense_declined';
     Notification::logNew($expense->user_id, $message, 'expense_declined', $notificationHash);
     //This event currently doesn't do anything
     event(new ExpenseWasDeclined($expense));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     foreach ($this->acsNodeRepository->getAll() as $device) {
         $this->info('Checking device ' . $device->name);
         /** @var $device \BB\Entities\ACSNode */
         if ($device->heartbeatWarning()) {
             $this->warn('Heartbeat warning');
             //There is a warning with the device, see if people have been notified
             $notificationHash = $device->device_id . md5($device->last_heartbeat->timestamp);
             $message = 'Nothing has been heard from device "' . $device->name . '"" in a while. ';
             $message .= 'The last update was ' . \Carbon\Carbon::now()->diffForHumans($device->last_heartbeat, true) . ' ago.';
             $role = Role::findByName('acs');
             foreach ($role->users()->get() as $user) {
                 $this->info('  Notifying ' . $user->name);
                 Notification::logNew($user->id, $message, 'device_contact', $notificationHash);
             }
         }
     }
 }
 public function adminUpdate($id)
 {
     $user = User::findWithPermission($id);
     $madeTrusted = false;
     if (\Input::has('trusted')) {
         if (!$user->trusted && \Input::get('trusted')) {
             //User has been made a trusted member
             $madeTrusted = true;
         }
         $user->trusted = \Input::get('trusted');
     }
     if (\Input::has('key_holder')) {
         $user->key_holder = \Input::get('key_holder');
     }
     if (\Input::has('induction_completed')) {
         $user->induction_completed = \Input::get('induction_completed');
     }
     if (\Input::has('profile_photo_on_wall')) {
         $profileData = $user->profile()->first();
         $profileData->profile_photo_on_wall = \Input::get('profile_photo_on_wall');
         $profileData->save();
     }
     if (\Input::has('photo_approved')) {
         $profile = $user->profile()->first();
         if (\Input::get('photo_approved')) {
             $this->userImage->approveNewImage($user->hash);
             $profile->update(['new_profile_photo' => false, 'profile_photo' => true]);
         } else {
             $profile->update(['new_profile_photo' => false]);
             event(new MemberPhotoWasDeclined($user));
         }
     }
     $user->save();
     if (\Input::has('approve_new_address')) {
         if (\Input::get('approve_new_address') == 'Approve') {
             $this->addressRepository->approvePendingMemberAddress($id);
         } elseif (\Input::get('approve_new_address') == 'Decline') {
             $this->addressRepository->declinePendingMemberAddress($id);
         }
     }
     if ($madeTrusted) {
         $message = 'You have been made a trusted member at Build Brighton';
         $notificationHash = 'trusted_status';
         Notification::logNew($user->id, $message, 'trusted_status', $notificationHash);
         event(new MemberGivenTrustedStatus($user));
     }
     if (\Request::wantsJson()) {
         return \Response::json('Updated', 200);
     } else {
         \Notification::success('Details Updated');
         return \Redirect::route('account.show', [$user->id]);
     }
 }