雄辩在哪里堆积

我的问题如下所示


$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>


神不在的星期二
浏览 104回答 2
2回答

缥缈止盈

因为 $data, $data1,$data2 指针指向内存中的同一个对象...解决这个问题:$data = Model::whereRaw(<condition 1>);$data1 =(clone $data)->whereRaw(<condition 2>)$data2 = (clone $data)->whereRaw(<condition 3>)

ABOUTYOU

尝试$data&nbsp; = Model::whereRaw(<condition 1>);$data_cloned = $data->replicate();$data1 = $data->whereRaw(<condition 2>);$data2 = $data_cloned->whereRaw(<condition 3>);return $data1->toSql();
打开App,查看更多内容
随时随地看视频慕课网APP