Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created February 9, 2019 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/f4534bceb44e1ea6ee5c3100a7578f35 to your computer and use it in GitHub Desktop.
Save uno-de-piera/f4534bceb44e1ea6ee5c3100a7578f35 to your computer and use it in GitHub Desktop.
<?php
$post = Post::with('tags', 'categories')->find(1);
$clone = $post->replicate();
foreach($post->tags as $tag)
{
$clone->tags()->attach($tag);
}
foreach($post->categories as $category)
{
$clone->categories()->attach($category);
}
$clone->push();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment