Пример #1
0
 /**
  * [handle description]
  *
  * @param  UserRepository $repository
  *
  * @return User
  */
 public function handle(UserRepository $repository)
 {
     // Currently authenticated user
     //$user = app('Dingo\Api\Auth\Auth')->user();
     //$user->hasRoleByName('Member');
     //$user->hasRole($user->getRoles()->toArray());
     Assertion::currentUserIsAdmin('You have no permission to create an Item');
     $user = $repository->get($this->id);
     Assertion::entityExists($user, "User with ID '{$this->id}' not found");
     return $user;
 }
 public function boot(UserRepository $repository)
 {
     $this->app[Auth::class]->extend('oauth', function ($app) use($repository) {
         $provider = new OAuth2($app['oauth2-server.authorizer']->getChecker());
         $provider->setUserResolver(function ($id) use($repository) {
             // Logic to return a user by their ID.
             return $repository->get($id);
         });
         /*$provider->setClientResolver(function ($id) {
               // Logic to return a client by their ID.
               return new \stdClass;
           });*/
         return $provider;
     });
 }