【发布时间】: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