Skip to content

Instantly share code, notes, and snippets.

@KyleGawryluk
Created December 12, 2013 19:17
Show Gist options
  • Save KyleGawryluk/7933748 to your computer and use it in GitHub Desktop.
Save KyleGawryluk/7933748 to your computer and use it in GitHub Desktop.
/**
* Post Relationship
* @param string $key API Key
* @param string $time API Timestamp
*
* Required Parameters
* 'module1' = (string) Portal Module Name
* 'id1' = (string) Record Sugar ID
* 'module2' = (string) Portal Module Name
* 'id2' = (string) Record Sugar ID
*
* @return mixed [description]
*/
public function postRelate($key, $time)
{
if ($this->emptyElementExists(Input::all())) {
return Response::make('Required Parameters Not Found', '400');
}
$var = (object) Input::all();
$class1 = ucfirst($var->module1);
$module1 = new $class1;
$relate1 = $module1->where('sugar_id','=',$var->id1)->first();
$class2 = ucfirst($var->module2);
$module2 = new $class2;
$relate2 = $module2->where('sugar_id','=',$var->id2)->first();
if (!$relate1 || !$relate2) {
return Response::make('Relationship Could Not Be Created', '400');
}
$relationship = $var->module2.'s';
$relate1->$relationship()->sync([$relate2->id]);
return Response::make('Relationship Created', '201');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment