public function deleted($model) { try { $noti = Notification::where("objectID", $model["post_id"])->where('sender_id', $model["user_id"])->delete(); } catch (Exception $e) { echo $e->getMessage(); } }
/** * API PUT Route to update a user's notification settings. * * @param User $user * * @return Response::json * * @todo There has to be a more efficient way to do this... We should probably only send changes from Angular. We can also separate the array matching into helper functions */ public function putNotifications(User $user) { if (Auth::user()->id !== $user->id) { return Response::json($this->growlMessage("You do not have permissions to edit this user's notification settings", "error")); } //Grab notification array $notifications = Input::get('notifications'); //Retrieve valid notification events $validNotifications = Notification::getUserNotifications(); $events = array_keys($validNotifications); //Loop through each notification foreach ($notifications as $notification) { //Ensure this is a known user event. if (!in_array($notification['event'], $events)) { return Response::json($this->growlMessage("Unable to save settings. Unknown event: " . $notification['event'], "error")); } //Grab this notification from the database $model = Notification::where('user_id', '=', $user->id)->where('event', '=', $notification['event'])->first(); //If we don't want that notification (and it exists), delete it if ($notification['selected'] === false) { if (isset($model)) { $model->delete(); } } else { //If the entry doesn't already exist, create it. //Otherwise, ignore ( there was no change ) if (!isset($model)) { $model = new Notification(); $model->user_id = $user->id; $model->event = $notification['event']; $model->type = "email"; $model->save(); } } } return Response::json($this->growlMessage("Settings saved successfully.", "success")); }
public function setAsRead(Request $request) { Notification::where('id', $request['id'])->update(['is_read' => 1]); return "Set notification nr " . $request['id'] . " as read."; }
public function findByBlockId($block_id) { return Notification::where('block_id', $block_id)->get(); }
/** * getDashboard * * regresa la informacion del escritorio del usuario * * @access public * @params * @return json * @autor Fernando Saavedra * * https://secure.kreativeco.com/se-banamex/api/dashboard * */ public function getDashboard() { $request = Request::all(); $user = Auth::user(); if ($user === null) { return Response::json(array("success" => true, "service" => __FUNCTION__, "error" => true, "message" => "Token no valido")); } $limit = 1; $coupon = Coupon::orderBy('id', 'DESC')->take($limit)->get(); $notification = Notification::where('notifications.id', '>', $request["notification_id"])->where('notifications.notification_type', '=', 1)->orderBy('id', 'DESC')->take(1)->get(); $notificationList = Notification::where('notifications.id', '>', $request["notification_id"])->orderBy('id', 'DESC')->get(); //dd( count($notificationList) ); return Response::json(array("success" => true, "service" => __FUNCTION__, "coupon" => $coupon, "notification" => $notification, "notification_list" => $notificationList, "count" => count($notificationList))); }
public static function user(User $user, $limit = 50) { $notifications = Notification::where('user_id', $user->id); $notifications->orderBy('created_at', 'desc'); $notifications = $notifications->paginate($limit); return $notifications; }