Skip to content

How can I get the {parameters} from the patterns of handlers in Middlewares? #316

Answered by Lukasss93
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

Just do this:

class CheckUserExistenceMiddleware
{
  public function __invoke(Nutgram $bot, $next)
  {
      [$action, $userID] = explode(':', $bot->callbackQuery()->data);

      $user = User::find($userID);
      if (! $user) {
          throw new Exception("User with id {$id} not found! ...");
      }
      // do stuff
      $next($bot);
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant