我有一個奇怪的問題,我沒有看到解決方案。請幫助我 :D所以我寫了 artisan 命令:user:seek-and-destroy,我想在其中破壞用戶和他的關系。命令代碼中的某處: $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()); }控制臺中的響應: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()命令響應看起來像是在工作,但實際上不是:c 記錄已保留在數據庫中查詢日志:delete from `users_payment_binding` where `user_id` = ? [475]一切看起來都很好,但是如果我再執行一次命令,我會得到相同的響應,因為delete()方法沒有從數據庫中刪除記錄。
1 回答

暮色呼如
TA貢獻1853條經驗 獲得超9個贊
讓我在這里解釋一些小細節,
$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 關注
- 182 瀏覽
添加回答
舉報
0/150
提交
取消