我有一个奇怪的问题,我没有看到解决方案。请帮助我 :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 关注
- 157 浏览
添加回答
举报
0/150
提交
取消