我的問題如下所示$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 關注
- 161 瀏覽
添加回答
舉報
0/150
提交
取消