/**
  * @param Request $request
  * @param Closure $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     //Generate the request id
     $requestId = Uuid::uuid1()->toString();
     //Add the request id processor to logger instance
     $this->log->addProcessors([new RequestIdProcessor($requestId)]);
     $response = $next($request);
     $response->headers->set('Request-Id', $requestId, false);
     return $response;
 }
 /**
  * Handle middleware
  *
  * @param Request $request
  * @param callable $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     //Get account
     $account = $this->getAccountFromRouting();
     //Set account in context
     $this->context->setAccount($account);
     //If the owner type is User
     if ($this->authorizer->getResourceOwnerType() == 'user') {
         //Find the user
         $user = $this->userRepository->find($this->authorizer->getResourceOwnerId());
         //If we have account in the route
         if ($account) {
             //Check if the user has access to the account
             if (!$user->isAssociateToAccount($account)) {
                 return $this->response->errorUnauthorized("You don't have access to the account {$account->uuid}");
             }
         }
         //Add context processor to log
         $this->log->addProcessors([new ContextProcessor($user, isset($account) ? $account : null)]);
         //Set the user in context
         $this->context->setUser($user);
     }
     // Set application locale
     $this->setApplicationLocale();
     return $next($request);
 }