/** * Display a listing of the resource. * * @param Request $request * @return Response */ public function index(Request $request) { if ($request->wantsJson()) { return Notification::where('user_id', Auth::id())->get(); } return view('notifications.index'); }
/** * 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; }