Пример #1
0
 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()]);
     }
 }