我的問題如下所示$data = Model::whereRaw(<condition 1>)$data1 = $data->whereRaw(<condition 2>)$data2 = $data->whereRaw(<condition 3>)每當(dāng)我打印時(shí)$data2->toSql()我都會(huì)得到這個(gè)select * from table where <condition 1> and <condition 2> and <condition 3>代替select * from table where <condition 1> and <condition 2>
2 回答

縹緲止盈
TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
因?yàn)?$data, $data1,$data2 指針指向內(nèi)存中的同一個(gè)對(duì)象...
解決這個(gè)問題:
$data = Model::whereRaw(<condition 1>);
$data1 =(clone $data)->whereRaw(<condition 2>)
$data2 = (clone $data)->whereRaw(<condition 3>)

ABOUTYOU
TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
嘗試
$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 關(guān)注
- 179 瀏覽
添加回答
舉報(bào)
0/150
提交
取消