我有一個(gè)奇怪的問(wèn)題,我沒(méi)有看到解決方案。請(qǐng)幫助我 :D所以我寫(xiě)了 artisan 命令:user:seek-and-destroy,我想在其中破壞用戶和他的關(guān)系。命令代碼中的某處: $paymentBinding = $user->payment_binding(); //HasMany relation if ($paymentBinding->count() > 0) { print_r($paymentBinding->get()->toArray()); $paymentBinding->delete(); //Methods like destroy(), DB::delete(), delete by id, also don't work print_r($paymentBinding->get()->toArray()); }控制臺(tái)中的響應(yīng):root@47a114f8ea98:/var/www/app# php artisan user:seek-and-destroy //Execute the comand//First print_r()Array( [0] => Array ( [user_id] => 475 [reference] => xxxxxxxxxxxxxxxxxxxx [identifier] => xxxxxxxxxxxxxxxxxxx [created_at] => 2018-06-26 14:56:10 [updated_at] => 2018-06-26 14:56:10 [id] => xxxx ))//Second print_r()Array()命令響應(yīng)看起來(lái)像是在工作,但實(shí)際上不是:c 記錄已保留在數(shù)據(jù)庫(kù)中查詢?nèi)罩荆篸elete from `users_payment_binding` where `user_id` = ? [475]一切看起來(lái)都很好,但是如果我再執(zhí)行一次命令,我會(huì)得到相同的響應(yīng),因?yàn)閐elete()方法沒(méi)有從數(shù)據(jù)庫(kù)中刪除記錄。
1 回答

暮色呼如
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
讓我在這里解釋一些小細(xì)節(jié),
$user->payment_binding(); // it will return a query builder instance
$user->payment_binding; // it will return payment_binding object
所以,嘗試像這樣刪除它
$user->payment_binding()->delete();
- 1 回答
- 0 關(guān)注
- 192 瀏覽
添加回答
舉報(bào)
0/150
提交
取消