/**
  * Wrap a command execution in a database transaction.
  *
  * @param  object    $command
  * @param  callable  $next
  * @return mixed
  *
  * @throws Exception
  * @throws Throwable
  */
 public function execute($command, callable $next)
 {
     $this->database->beginTransaction();
     try {
         $returnValue = $next($command);
         $this->database->commit();
     } catch (Exception $exception) {
         $this->database->rollBack();
         throw $exception;
     } catch (Throwable $exception) {
         $this->database->rollBack();
         throw $exception;
     }
     return $returnValue;
 }