3

i have facing a problem at laravel.

I want to replicate/clone of collection after apply filter the collection.

code is below:

/* Scope function */         
    $plansFilterIndexes=Plans::PlansFilterFields();
     $planFilters=Plans::FilterFieldsSerial($query);
     /* Create Plans collection */

     $PlansAll=Plans::all();

    /* Plans Filter by url 
     * here checking $planFilter  indexes IS AVALIABLE AT 
     *  DEFINED  INDEX $plansFilterIndexes
     */
    $query = null;
        foreach($planFilters as $eachIndexKey => $eachIndexValue):
        echo $eachIndexKey.'------'.$eachIndexValue.'<br/>';
        if(array_search($eachIndexKey, $plansFilterIndexes) != false):

            $PlansAll = $PlansAll->where($eachIndexKey, $eachIndexValue);
        endif;
    endforeach;
    //dd($PlansAll);
    /* Clone collection into new once for copy */

    $PlansAllClone =$PlansAll->replicate();
    dd($PlansAllClone);

Try with Clone an Eloquent object including all relationships? solution but did not get result

Show error: Method replicate does not exist.

It not working.

Question:

Why $PlansAllClone =$PlansAll->replicate(); is failed to give result. and if it not possiable ,show i will achieve it.

Community
  • 1
  • 1
Amit Bera
  • 7,581
  • 7
  • 31
  • 57

1 Answers1

1

Replicate is a method for cloning a model into a new non existing instance not for cloning a Collection.

replicate is used like this:

$newPlansInstance = Plans::replicate();

It can except an optional argument which is an array of exceptions.

What exactly are you trying to accomplish ?

funkenstein
  • 293
  • 6
  • 17