Last active
July 20, 2019 20:39
-
-
Save leandroruel/448172c0562eb5dfbd6a01b88320bd8b to your computer and use it in GitHub Desktop.
creates a clone of a model and his relationships
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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