public function view($name, $data = array()) { $detect = $this->detectDay(); $data['day'] = $detect[0]; $data['name_day'] = $detect[1]; $data['logged'] = Auth::check(); $data['user'] = Auth::get(); $view = new View($name, $data); return $view->render(); }
public function update() { $user = Auth::get(); if ($user) { $notifications = $user->notifications(); foreach ($notifications as $notification) { $notification->new = 0; $notification->update(); } } }
public function fromFollowers() { $user = Auth::get(); $posts = []; $count_posts = 0; if ($user) { $followers = $user->following(); $ids = []; foreach ($followers as $follower) { $ids[] = $follower->id; } if (count($ids) > 0) { $ids = implode(',', $ids); $post = new Post(); $posts = $post->in($ids); $count_posts = count($posts); } } return $this->view('followers-posts', compact('posts', 'count_posts')); }
public function follow($data) { $user = Auth::get(); if ($user) { if ($data->type == 1) { if (!$user->isFollowing($data->id)) { $user->follow($data->id); return json_encode(['success' => 'Zapnutie sledovania bolo úspešné.']); } else { return json_encode(['error' => 'Už sledujete tohto používateľa!']); } } else { if ($user->isFollowing($data->id)) { $user->unfollow($data->id); return json_encode(['success' => 'Zrušenie sledovania bolo úspešné.']); } else { return json_encode(['error' => 'Najprv musíte sledovať tohto používateľa!']); } } } return json_encode(['error' => 'Musíte byť prihlásený!']); }
public function update($request) { $validate = $this->validate($request, $this->rules); if ($validate->errors() == 0 && Auth::get()) { $conversation = new Conversation(); $conversation = $conversation->find((int) $request->id); if ($conversation) { if ($conversation->hasAccess()) { $conversation->updated_at = date('Y-m-d H:i:s'); $conversation->update(); $message = new Message(); $message->conversation_id = $conversation->id; $message->sender_id = Auth::get()->id; $message->text = nl2br(htmlspecialchars($request->text)); $message->save(); $notification = new Notification(); $notification->text = 'Používateľ ' . Auth::get()->nick . ' vám poslal novú správu!'; $notification->user_id = $conversation->getUserId(); $notification->link = 'sprava/' . $conversation->id; $notification->save(); return json_encode(['success' => 'Správa bola úspešne odoslaná!']); } else { return json_encode(['errors' => ['Nemáte prístup!']]); } } } else { return json_encode(['errors' => $validate->getErrors()]); } }