Laravel replicate()函数不适用于模型集合


Laravel replicate() function is not working for model collection

我在laravel遇到了一个问题。

我想在应用筛选集合后复制/克隆集合

代码如下:

/* 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);

尝试克隆一个包含所有关系的Eloquent对象?解决方案,但没有得到结果

显示错误:Method replicate does not exist.

它不起作用。

问题:

为什么$PlansAllClone=$PlansAall->replicate();未能给出结果。如果不可能,显示我会实现。

Replicate是一种将模型克隆到新的不存在实例中的方法,而不是克隆Collection。

复制是这样使用的:

$newPlansInstance = Plans::replicate();

它可以排除一个可选参数,该参数是一个异常数组。

你到底想完成什么?