我有一个奇怪的问题,我没有看到解决方案。请帮助我 :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()方法没有从数据库中删除记录。
暮色呼如