#Get path or URL from Route object?

5 messages · Page 1 of 1 (latest)

white viper
#

Is there a way to get the full path, or at least a full URL, from an Illuminate\Routing\Route object? I understand I can use ->uri to get the path relative to the application root and use the url helper to get a full URL; but, is there a way to get the full, domain-relative path or the full URL directly from the Route object?

For example, if the application is located at example.com/foo, and the route URI is /bar/update, is there a method or attribute directly on the Route object that will give me either /foo/bar/update or http[s]://example.com/foo/bar/update?

indigo tartan
#

I'm guessing something like $fullUrl = url('/path/to/resource');

mint swift
#

Like in what scenario would you want to do this?

nimble plover
#

It depends on the context. The Route stores the definition of a route, and it only contains the actual route parameters if you get it from $request->route(), and in that case you could just ask the request object for the url.

#

But in either case, Route doesn't necessarily know anything about the domain (unless it's part of the route definition), and it also doesn't know which protocol (http or https) should be used.