PHP code example of bkwld / cloner

1. Go to this page and download the library: Download bkwld/cloner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bkwld / cloner example snippets


Bkwld\Cloner\ServiceProvider::class,

'providers' => [
    /*
    * Package Service Providers...
    */
    Bkwld\Cloner\ServiceProvider::class,
],

class Article extends Eloquent {

   use \Bkwld\Cloner\Cloneable;
}

$clone = Article::first()->duplicate();

$clone = Article::first()->duplicateTo('production');

class Article extends Eloquent {
   use \Bkwld\Cloner\Cloneable;

   protected $cloneable_relations = ['photos', 'authors'];

   public function photos() {
       return $this->hasMany('Photo');
   }

   public function authors() {
        return $this->belongsToMany('Author');
   }
}

class Photo extends Eloquent {
   use \Bkwld\Cloner\Cloneable;

   protected $clone_exempt_attributes = ['uid', 'source'];

   public function article() {
        return $this->belongsTo('Article');
   }

   public function onCloning($src, $child = null) {
        $this->uid = str_random();
        if($child) echo 'This was cloned as a relation!';
        echo 'The original key is: '.$src->getKey();
   }
}

class Photo extends Eloquent {
   use \Bkwld\Cloner\Cloneable;

   protected $cloneable_file_attributes = ['image'];

   public function article() {
        return $this->belongsTo('Article');
   }
}

App::singleton('cloner.attachment-adapter', function($app) {
   return new CustomAttachmentAdapter;
});