/** * Adds a user to the database * * @return json */ public function add() { $data = Input::all(); $add = ['community_id' => $data['community_id'], 'nickname' => $data['nickname'], 'avatar' => $data['avatar'], 'enabled' => $data['state']]; try { $user = $this->users->add($add); } catch (Exception $e) { // 23000: Integrity constraint violation = Duplicate Entry if ($e->getCode() == '23000') { return $this->jsonResponse(400, false, 'User already exists!'); } return $this->jsonResponse(400, false, $e->getMessage(), null, $e->getCode()); } $guest = $this->roles->getFirst('name', 'guest'); if (!is_null($data['role'])) { foreach ($data['role'] as $role) { $this->users->assignRole($user, $role['id']); } } $this->users->assignRole($user, $guest['id']); //Event::fire('user.add', $user); return $this->jsonResponse(200, true, 'User has been successfully been added!', $this->users->getWithRoles($user['id'])); }