【问题标题】:Laravel replicate() function is not working for model collectionLaravel 复制()函数不适用于模型集合
【发布时间】:2016-04-09 02:54:57
【问题描述】:

我在 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);

尝试使用Clone an Eloquent object including all relationships? 解决方案,但没有得到结果

显示错误: Method replicate does not exist.

它不工作。

问题:

为什么 $PlansAllClone =$PlansAll->replicate();未能给出结果。 如果它不可能,表明我会实现它。

【问题讨论】:

    标签: php collections model laravel-5.1


    【解决方案1】:

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

    replicate 是这样使用的:

    $newPlansInstance = Plans::replicate();
    

    它可以排除作为异常数组的可选参数。

    你到底想完成什么?

    【讨论】:

      猜你喜欢
      • 2017-10-02
      • 2015-08-09
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      相关资源
      最近更新 更多