Skip to content

Instantly share code, notes, and snippets.

@giltotherescue
Created March 17, 2015 00:34
Show Gist options
  • Save giltotherescue/342426bc39422f012fe5 to your computer and use it in GitHub Desktop.
Save giltotherescue/342426bc39422f012fe5 to your computer and use it in GitHub Desktop.
if ($portfolio = DB::transaction(function() {
$orig = Portfolio::findOrFail(Input::get('copy_portfolio'));
$orig->load('authors', 'audiences', 'editorComment', 'uploads');
$portfolio = $orig->replicate();
$portfolio->title = Input::get('title');
$portfolio->push();
foreach ($orig->authors as $a)
{
$portfolio->authors()->attach($a);
}
foreach ($orig->audiences as $a)
{
$new = new Audience();
$new->fill($a->getAttributes());
$portfolio->audiences()->save($new);
}
foreach ($orig->editorComment as $a)
{
$new = new \EditorComment();
$new->fill($a->getAttributes());
$portfolio->editorComment()->save($new);
}
foreach ($orig->uploads as $a)
{
$new = new \Upload();
$new->fill($a->getAttributes());
$portfolio->uploads()->save($new);
}
$portfolio->save();
return $portfolio;
})) {
$saved = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment