我的问题如下所示$data = Model::whereRaw(<condition 1>)$data1 = $data->whereRaw(<condition 2>)$data2 = $data->whereRaw(<condition 3>)每当我打印时$data2->toSql()我都会得到这个select * from table where <condition 1> and <condition 2> and <condition 3>代替select * from table where <condition 1> and <condition 2>
2 回答
缥缈止盈
TA贡献2041条经验 获得超4个赞
因为 $data, $data1,$data2 指针指向内存中的同一个对象...
解决这个问题:
$data = Model::whereRaw(<condition 1>);
$data1 =(clone $data)->whereRaw(<condition 2>)
$data2 = (clone $data)->whereRaw(<condition 3>)
ABOUTYOU
TA贡献1812条经验 获得超5个赞
尝试
$data = Model::whereRaw(<condition 1>);
$data_cloned = $data->replicate();
$data1 = $data->whereRaw(<condition 2>);
$data2 = $data_cloned->whereRaw(<condition 3>);
return $data1->toSql();
- 2 回答
- 0 关注
- 103 浏览
添加回答
举报
0/150
提交
取消