I try this:
public function destroy($id) { DB::beginTransaction(); try { $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()]; } }
If the code is executed, $this->product_repository->delete($id) does not work / cannot be deleted.
But this is: $product->categories()->detach(); It is deleted / deleted.
How if product deletion failed, delete category also failed?
Success man
source share