예제 #1
0
 /**
  * @param Request $request
  * @param Entry   $entry
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function storeReply(Request $request, $entry)
 {
     $this->validate($request, EntryReply::rules());
     if (user()->isBanned($entry->group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik został zbanowany w wybranej grupie.'], 400);
     }
     $reply = new EntryReply();
     $reply->text = request('text');
     $reply->user()->associate(user());
     $entry->replies()->save($reply);
     return response()->json(['status' => 'ok', '_id' => $reply->getKey(), 'reply' => $reply]);
 }
예제 #2
0
 public function editEntry(Request $request)
 {
     $id = hashids_decode($request->input('id'));
     $class = $request->input('type') == 'entry_reply' ? EntryReply::class : Entry::class;
     $entry = $class::findOrFail($id);
     if (!$entry->canEdit()) {
         return Response::json(['status' => 'error', 'error' => 'Pojawiła się już odpowiedź na twój wpis.']);
     }
     $this->validate($request, EntryReply::rules());
     $entry->text = Input::get('text');
     $entry->save();
     return Response::json(['status' => 'ok', 'parsed' => $entry->text]);
 }