我试试这个: p>
public function destroy($ id )
{
DB :: beginTransaction();
尝试{
$ product = $ this-> product_repository-> find($ id);
$ result = $ product-> categories() - > detach();
if($ result){
list($ status,$ instance)= $ this-> product_repository-> delete($ id);
}
DB :: commit ();
return ['status'=> true,'data'=> $ status];
} catch(\ Exception $ e){
DB :: rollback();
return [' status'=> false,'message'=> $ e-> getMessage()];
}
}
code> pre>
如果代码已执行 , $ this-> product_repository-> delete($ id) code> not working / not success delete。 p>
但是: $ product-> categories() - > detach(); code>,它的工作/成功删除。 p>
\ n 如果删除产品失败,删除类别也失败了? p>
div>