Example #1
0
 public function postGroup($id = null)
 {
     if (Input::has('id')) {
         $group = Group::find(Input::get('id'));
         if (!$group->isGroupOwner(Auth::user()->id)) {
             return Response::json($this->growlMessage('You cannot modify a group you do not own.', 'error'));
         }
         $message = "Your group has been updated!";
     } else {
         $group = new Group();
         $group->status = Group::STATUS_PENDING;
         $message = "Your group has been created! It must be approved before you can invite others to join or create documents.";
     }
     $postData = array('name', 'display_name', 'address1', 'address2', 'city', 'state', 'postal_code', 'phone_number');
     foreach ($postData as $field) {
         $group->{$field} = Input::get($field);
     }
     if ($group->validate()) {
         $group->save();
         $group->addMember(Auth::user()->id, Group::ROLE_OWNER);
         if ($group->status === Group::STATUS_PENDING) {
             Event::fire(MadisonEvent::VERIFY_REQUEST_GROUP, $group);
         }
         return Response::json($this->growlMessage($message, 'success'));
     } else {
         return Response::json($this->growlMessage($group->getErrors()->all(), 'error'), 400);
     }
 }