public function create($request) { $validate = $this->validate($request, $this->rules); if ($validate->errors() == 0) { $user = Auth::get(); if ($user) { $post = new Post($request); $post->user_id = Auth::getUserId(); $post->text = nl2br($post->text); $post->update(); foreach ($user->followers() as $follower) { $notification = new Notification(); $notification->text = 'Používateľ ' . $user->nick . ' pridal nový príspevok s nadpisom ' . $post->title . '!'; $notification->user_id = $follower->id; $notification->link = 'prispevok/' . $post->id; $notification->save(); } return json_encode(['success' => 'Hejt bol úspešne pridaný!']); } } else { return json_encode(['errors' => $validate->getErrors()]); } }
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()]); } }