Home > Back-end >  Why pathInfo shows null if is not null?
Why pathInfo shows null if is not null?

Time:06-16

The dd($request) shows a pathInfo #pathInfo: "/nova-api/post-tags/20/update-fields". And I want to get that value, more specifically I want to check if "post-tags" is in the url.

However dd($request->pathInfo); shows:

null

But its not null as can be seen below:

Laravel\Nova\Http\Requests\NovaRequest {#1703
  #container: Illuminate\Foundation\Application {#2
    #basePath: "/var/www/src"
    #hasBeenBootstrapped: true
    #booted: true
    ....
      "request" => Illuminate\Http\Request {#43
        ...
        #routeResolver: Closure() {#655
          class: "Illuminate\Routing\Router"
          ...
          }
          file: "/var/www/src/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
          line: "650 to 652"
        }
         attributes: Symfony\Component\HttpFoundation\ParameterBag {#45
          #parameters: []
        }
         request: Symfony\Component\HttpFoundation\ParameterBag {#51
          #parameters: array:5 [ …5]
        }
         query: Symfony\Component\HttpFoundation\ParameterBag {#51}
         server: Symfony\Component\HttpFoundation\ServerBag {#47
          #parameters: array:63 [ …63]
        }
         files: Symfony\Component\HttpFoundation\FileBag {#48
          #parameters: []
        }
         cookies: Symfony\Component\HttpFoundation\ParameterBag {#46
          #parameters: array:4 [ …4]
        }
         headers: Symfony\Component\HttpFoundation\HeaderBag {#49
          #headers: array:21 [ …21]
          #cacheControl: array:1 [ …1]
        }
        #content: ""
        #languages: null
        #charsets: null
        #encodings: null
        #acceptableContentTypes: null
        #pathInfo: "/nova-api/post-tags/20/update-fields"
        #requestUri: "/nova-api/post-tags/20/update-fields?editing=true&editMode=update&viaResource=&viaResourceId=&viaRelationship="
        #baseUrl: ""
        #basePath: null
        #method: "GET"
        #format: null
        ...
      }
      ....
}

Do you know what can be the issue?

CodePudding user response:

According to the API docs, you should be able to do:

$request->path()

to get the path info for the request.

CodePudding user response:

$request->pathInfo is a protected property in symfony/http-foundation/Request.php. You need to access it $request->getPathInfo().

  • Related