use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals();
if ($request->isMethod('POST')) { // Handle POST request } else { // Handle other HTTP methods }
if ($request->isMethod(['GET', 'HEAD', 'OPTIONS'])) { // Allow read-only requests } else { // Handle other HTTP methods }Overall, the Request isMethod() function is a useful tool for checking the HTTP method used in a request and responding accordingly. It is part of the Symfony\Component\HttpFoundation package library for PHP.