public function postCreate() { // create a single model // $projectInvitation = new ProjectInvitation(array('project_uid' => Input::get('project_uid'), 'invitation_key' => GUID::create(), 'inviter_uid' => Input::get('inviter_uid'), 'invitee_name' => Input::get('invitee_name'), 'email' => Input::get('email'))); $user = User::getByEmail(Input::get('email')); if ($user) { if (ProjectMembership::where('user_uid', '=', $user->user_uid)->where('project_uid', '=', Input::get('project_uid'))->where('delete_date', '=', null)->first()) { return Response::json(array('error' => array('message' => Input::get('invitee_name') . ' is already a member')), 409); } } $invite = ProjectInvitation::where('project_uid', '=', Input::get('project_uid'))->where('email', '=', Input::get('email'))->where('accept_date', '=', null)->where('decline_date', '=', null)->first(); if ($invite) { return Response::json(array('error' => array('message' => Input::get('invitee_name') . ' already has a pending invitation')), 409); } // Model valid? // if ($projectInvitation->isValid()) { $projectInvitation->save(); $projectInvitation->send(Input::get('confirm_route'), Input::get('register_route')); return $projectInvitation; } else { $errors = $projectInvitation->errors(); return Response::make($errors->toJson(), 409); } }