DB::beginTransaction();
try {
$project = Project::find($id);
$project->users()->detach();
$project->delete();
DB::commit();
} catch (Exception $ex) {
DB::rollback();
return response()->json(['error' => $ex->getMessage()], 500);
}
DB::beginTransaction();
try {
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();
// all good
} catch (Exception $e) {
DB::rollback();
// something went wrong
}
DB::beginTransaction();
try { /** Statement */ DB::commit(); }
catch (Exception $e) { /** Statement if failed */ DB::rollback(); }
DB::transaction(function() {
//
});