Esempio n. 1
0
 public function store(Request $request)
 {
     if (Input::has('group')) {
         Input::merge(['groupname' => request('group')]);
     }
     $this->validate($request, Entry::rules());
     $group = Group::name(request('group'))->firstOrFail();
     $group->checkAccess();
     if (user()->isBanned($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik został zbanowany w wybranej grupie.'], 400);
     }
     if ($group->type == 'announcements' && !user()->isModerator($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik nie może dodawać wpisów w tej grupie.'], 400);
     }
     $entry = new Entry();
     $entry->text = request('text');
     $entry->user()->associate(user());
     $entry->group()->associate($group);
     $entry->save();
     return response()->json(['status' => 'ok', '_id' => $entry->getKey(), 'entry' => $entry]);
 }
Esempio n. 2
0
 public function addEntry(Request $request)
 {
     $this->validate($request, Entry::rules());
     $group = Group::name(Input::get('groupname'))->firstOrFail();
     $group->checkAccess();
     if (Auth::user()->isBanned($group)) {
         return Response::json(['status' => 'error', 'error' => 'Zostałeś zbanowany w wybranej grupie']);
     }
     if ($group->type == 'announcements' && !Auth::user()->isModerator($group)) {
         return Response::json(['status' => 'error', 'error' => 'Nie możesz dodawać wpisów do wybranej grupy']);
     }
     $entry = new Entry();
     $entry->text = Input::get('text');
     $entry->user()->associate(Auth::user());
     $entry->group()->associate($group);
     $entry->save();
     return Response::json(['status' => 'ok']);
 }