Skip to content

Instantly share code, notes, and snippets.

@leandroruel
Last active July 20, 2019 20:39
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 leandroruel/448172c0562eb5dfbd6a01b88320bd8b to your computer and use it in GitHub Desktop.
Save leandroruel/448172c0562eb5dfbd6a01b88320bd8b to your computer and use it in GitHub Desktop.
creates a clone of a model and his relationships
<?php namespace App\Http\Controllers;
use App\MyModel;
class CloneController extends Controller
{
/**
* Replicate a model and his relationships
*
* @param $id
*/
public function clone($id)
{
$model = MyModel::find($id);
$clone = $model->replicate();
$clone->push();
return $clone;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment