How to check the request type in Laravel and how to retrieve the requested path

The Illuminate\Http\Request instance provides different methods for examining an incoming HTTP request and extends the Symfony\Component\HttpFoundation\Request class. A few of the important methods are shown below.

Retrieve Request Path

The path method returns the request’s path information. Suppose, if an incoming request is targeted at http://example.com/hello/abc, the path method will return hello/abc:

The path method returns information about a request’s path.

$uri = $request->path();

Inspect the Request Path / Route

The is method is used to verify an incoming request path, if it matches a given pattern. The * character can be used as a wildcard when utilizing this method:

if ($request->is('admin/*')) {
    //
}

The routeIs method helps determine if an incoming request has matched a named route.

Retrieve The Request Method

In order to identify the type of HTTP request, you may use the method() function and then check it by isMethod() function to identify the request.

$method = $request->method();
 
if ($request->isMethod('post')) {
    //
}