コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 public function after($number)
 {
     if (Input::has('key') == false) {
         return $this->response->errorUnauthorized();
     }
     $ads = Ad::whereRaw('id > ' . $number)->orderBy('message_number', 'DESC')->paginate(50);
     // Pass this array (collection) into a resource, which will also have a "Transformer"
     // This "Transformer" can be a callback or a new instance of a Transformer object
     // We type hint for array, because each item in the $ads var is an array
     return $this->response->withPaginator($ads, new AdTransformer());
 }